Академический Документы
Профессиональный Документы
Культура Документы
PRACTICAL-3
08IT32(31)
Page 26
Image Processing
1) Consider the following matrix
Generate the above matrix and show the equitant grayscale image. i.e.
Ans: function genmatrix() for i=1:256 for j=1:256 a(i,j)=j-1; end end map=colormap(gray(256)); imshow(a,map);
08IT32(31)
Page 27
Image Processing
2) Generate the following matrix of size 256 x 256. (It will generate circle centered
at (128,128) and radius=80 pixels).
Ans: function circle() for i=1:256 for j=1:256 if sqrt((i-128)*(i-128)+(j-128)*(j-128))<80 b(i,j)=255; else b(i,j)=0; end end end map=colormap(gray(2)); imshow(b);
08IT32(31)
Page 28
Image Processing
Ans: function circle1() for i=1:256 for j=1:256 a(i,j)=j-1; end end for i=1:256 for j=1:256 if sqrt((i-128)*(i-128)+(j-128)*(j-128))<80 b(i,j)=255; else 08IT32(31) Page 29
Image Processing
b(i,j)=0; end c(i,j)=(a(i,j)*b(i,j))/255; end end map=colormap(gray(256)); imshow(c,map);
4) Make a matlab function subsample (image,factor), where image is the image to be sub sampled and factor specifies the sub sampling factor (if factor is 1, 1024 x 1024 image should be sub-sampled to 512 x 512, if it is 2 then it should be sub sampled to 256 x 256). Function must display the sub-sampled image at the original size. Ans: function subsample(image,factor) a=imread(image); for i=1:factor a=a(:,1:2:end); a=a(1:2:end,:); end imshow(a); [x y z]=size(a); for j=1:factor k=1; for i=1:y 08IT32(31) Page 30
Image Processing
b(:,k)=a(:,i); b(:,k+1)=a(:,i); k=k+2; end a=b; [x y z]=size(a); k=1; for i=1:x b(k,:)=a(i,:); b(k+1,:)=a(i,:); k=k+2; end a=b; [x y z]=size(a); end imshow(b);
>>img(rice.png,2) 5) Demonstrate the effect of false contouring due to reduction in number of gray levels. Use imshow (image, number of gray levels). Ans: function img(image,gry) a=imread(image); imshow(a,gry);
08IT32(31)
Page 31
Image Processing
>>img(rice.png,2)
08IT32(31)
Page 32