This help is just for you to start the assignment.
Q1. In Matlab workspace,
read, display and get properties of the images
cameraman.tif and
lena_grey.tif.
- Use the imfinfo, imread, imshow, whos, size, and
display the two images in one row in a figure window.
- create an assignment folder, say a1
- download the two images and save them to the folder a1
- start Matlab, then do a self-tutorial using an online tutirial if you never used Matlab before
- change the current working directory to a1
- try the following commands
>> imfinfo('cameraman.tif')
>> imshow('cameraman.tif')
>> f = imread('cameraman.tif'); % use ; r
>> size(f)
>> imshow(f)
>> whos f
>> subplot(1, 2, 1), imshow(f)
>> subplot(1, 2, 2), imshow('lena_grey.tif')
do more practices on matrix to find the mean and Std
mean2(f)
std2(f)
กก
- Examine the image properties
of the two images and supply the requested data below.
from the above operations, fill the following tables for both images
cameraman.tip lena_grey.tif
Width 256 ??
Height 256 ??
Color depth
??
??
File size ?? ??
Image color type ?? ??
Mean pixel value ?? ??
Std. deviation ?? ??
Q2.
Write a Matlab m file to load the image autumn.tif and
then save the image file in the following format.
.tiff Tagged Image File Format (or .tif)
.jpeg Joint Photographic Experts Group (or .jpg)
.bmp Windows Bitmap
name you m file as a1q2.m
>> edit a1q2.m
in the m file you can
function a1q2(filename)
img = imread(filename);
imwrite(......); % you can use file name like a1q2.tif, etc
...
...
...
make sure that the file you created can be open.
Q3.
Write an m files to do the following:
- create a black and white
image of size 512 x 512 with a square of edge length 200 in the middle, and save the image as
sqaure.gif
- read the above the square.tif image and rotate image 45 degree anti-clockwise
and then scale the square by a factor of 1.414 (with respect to the center of
the square). then add the two images
together, save the image to the file nested_squares.gif
function a1q3()
%s1 - subquestion 1
img = uint8(ones(512,512)*255); % 8 bits, unsigned data type, this is to create a while image
for i=1:1:200
..... % change the pixel value at the square position to be 0, (black)
end
imshow( ); % testing
imwrite(... );
%s2
img = imread(... );
dim = size(img);
img2 = uint8(ones(dim)); % to hold the transformed image
img3 = img; % to hold the final resuluting image
for i=1:1:dim(1)
for j=1:1:dim(2)
if (img(i,j) == 0) % only transform those white points,
you need to translate the square to the origin before scaling, and translate
back after rotation.
....
end
end
end
imshow(img3);
imwrite(.......);
- You can also write an m
file to create your own art image.
Q4.
Write a function that converts the RGB values to grayscale values by forming the
following standard weighted sum of the R, G, and B components:
0.2989 * R + 0.5870 * G + 0.1140 * B. The function has calling prototype [grayimage_out] = rgbtograyscale(rgbimage_in).
Testing your function by
autumn.tif
function temp = rgbtograyscale(filename)
img = imread(filename);
......
dim = size(img);
...
temp = uint8(zeros(size(1), size(2)))
.........
imshow(temp);
Q5. Write
a Matlab function to convert an image
into a binary image using by thresholding m. Use function prototype
convert2binary('image_name', m) . Test your program using
this image with m = 128.
function convery2binary(filename, m)
img=imread(filename);
....
imshow(img);
imwrite(....);
Q6.
function instensitySpread(filename,lmin,lmax)
img=imread(filename);
fmin=min(img(:));
fmax=max(img(:));
r=double(lmax-lmin)/double(fmax-fmin);
img(i,j)=.....
imshow(img);
imwrite(img,'q6.tif');
Q8.
Q9.
mask of size m can be coreated by
w=zeros(m,m);
m = m-1;
for i=-m/2:+m/2
for j=-m/2:+m/2
w(i+m/2+1,j+m/2+1)=gauss(i,j,1);
end
end
function g = gauss(x,y,z)
g = exp(-(x^2+y^2)/(2*z^2));
Q10.
You can use the following for a simple solution
img=imread(filename);
imgd=im2double(img);
gw4=imfilter(imgd,filter_w4);
gw8=imfilter(imgd,filter_w8);
gnw4=imfilter(imgd,filter_nw4);