Wednesday, June 4, 2008

Assignment 7

(1)Sub-square average shrink

function [ smim ] = shrink( picture, f )
Mp = floor(size(picture,1)*f);
Np = floor(size(picture,2)*f);
smim(:,:,1)=zeros(Mp,Np);
smim(:,:,2)=zeros(Mp,Np);
smim(:,:,3)=zeros(Mp,Np);

for i = 0:(Mp-1)
for j = 0:(Np -1)
for x = floor(i/f):ceil((i+1)/f)-1
for y = floor(j/f):ceil((j+1)/f)-1
ival = picture(x+1,y+1,:);
if(x (i+1)/f)
ival = ival*(1+((i+1)/f)-(x+1));
end
if (y< ival =" ival*(1-(j/f)+y);"> (j+1)/f)
ival =ival*(1-(y+1)+(j+1)/f);
end

smim(i+1,j+1,:) = smim(i+1,j+1,:)+ival;
end;
end;
smim(i+1,j+1,:) = smim(i+1,j+1,:)/(1/f)^2;
end
end


(2) Nearest pixel shrink

function [ smim ] = shrink2( picture,f )

Mp = floor(size(picture,1)*f);
Np = floor(size(picture,2)*f);

for i = 1:Mp
for j = 1:Np
a = round(i/f);
b = round(j/f);
smim(i,j,:) = picture(a,b,:);
end
end

(3) Bilinear interpolation shrink

function [ smim ] = shrink3( picture,f )
Mp = floor(size(picture,1)*f);
Np = floor(size(picture,2)*f);

for i = 1:Mp
for j = 1:Np
a = i/f;
b = j/f;
r = floor(a);
s = floor(b);
if (r>0) && (r 0) && (s smim(i,j,1) = [1-(a-r),a-r]*[picture(r,s,1), picture(r,s+1,1); picture(r+1,s,1),picture(r+1,s+1,1)]*[1-b+s;b-s];
smim(i,j,2) = [1-(a-r),a-r]*[picture(r,s,2), picture(r,s+1,2); picture(r+1,s,2),picture(r+1,s+1,2)]*[1-b+s;b-s];
smim(i,j,3) = [1-(a-r),a-r]*[picture(r,s,3), picture(r,s+1,3); picture(r+1,s,3),picture(r+1,s+1,3)]*[1-b+s;b-s];
end
end
end
shrink selection

Comparing the following three selection it is clear that the second method produces an image with the highest contrast and worst color transitions(smoothness) , since nothing is averaged. The first method is the smoothest, but it has the lowest contrast. The third method is something in the middle between the first two.






shrink 2 selection





shrink 3 selection






I only included one scale factor 0.1 and 0.25 picture, since on the blog they all look the same. Even the 0.75 images look indistinguishable to me. Of course when I zoom in to the actual images there are differences.



imshow(shrink(Jade,0.75))

imshow(shrink2(Jade,0.75))

imshow(shrink3(Jade,0.75))







imshow(shrink(bluelines,0.75))

imshow(shrink2(bluelines,0.75))

imshow(shrink3(bluelines,0.75))


imshow(shrink(rainbow,0.75))


imshow(shrink2(rainbow,0.75))

imshow(shrink3(rainbow,0.75))

No comments: