Hybrid image for cat&dog.
The goal of this project is to use my_imfilter() function to create hybrid images which are static images that can have different interpretation in terms of different viewing distance. We use my_imfilter() function to cut off high frequency of one image and low frequency of the other one, then combine the two filtered images together to get hybrid image. my_imfilter() function imitates the default behavior of built in function imfilter() which is provided in Matlab.
The hybrid image at the right combines the low-pass version of dog.bmp and high-pass version of cat.bmp. So if you look at the image from very close, you will see a cat, but if you look at it from far away, you will see a dog.
Image1
Image2
[height,width,dim]=size(image);
[row,col]=size(filter);
output=zeros(height,width,dim); %create output image
tempM=zeros(row,col,dim);
for i=1:height %every element in image
for j=1:width
counter1=1;
for m=i-(row-1)/2:i+(row-1)/2 %each neighbourhood
counter2=1;
for n=j-(col-1)/2:j+(col-1)/2
for k=1:dim
if (m<1)||(m>height)||(n<1)||(n>width) %zero padding if outside the image boundary
tempM(counter1,counter2,k)=0;
else
tempM(counter1,counter2,k)=image(m,n,k);
end
end
counter2=counter2+1;
end
counter1=counter1+1;
end
for k=1:dim
temp=tempM(1:row,1:col,k).*filter;
sumTemp=sum(sum(temp));
output(i,j,k)=sumTemp;
end
end
end
low_frequencies = my_imfilter(image1,filter);
high_frequencies = image2-my_imfilter(image2,filter);
hybrid_image = low_frequencies+high_frequencies;
low high hybrid |
low high hybrid |
low high hybrid |
low high hybrid |
low high hybrid |
The hybrid image consists of the low frequency version of da_Vinci.jpg and the high frequency version of Mona_Lisa.jpg. As a result, if you look at the image from very close, you will see Mona Lisa. But if you look at the image from far away, you will see the portrait of da Vinci.
low high hybrid |