Example of a right floating element.
When we look at the image, its a cat but as we go few meters away it starts looking like a dog. Also if we enlarge the same image it looks like a cat, whereas when we reduce the size its a dog. What is it basically? What is happening is that we are cheating our eyes by passing particular frequencies at a particular distance. It’s basically hybrid image of both dog and Cat.
Thus we can say that we are superimposing some parameters of first image with some of the other, forming an image with characteristics of both the images which gets highlightened with change in location. Thus to produce such image, we need to carefully choose the parameters of the image. If we observe, one image is sharpened and the other is blurred. In technical terms, we are allowing high frequencies to pass by using a high pass filter whereas the other image is processed by low pass filter.
A filter is basically a tool used on an image for performing processes like sharpening, smoothing etc. There is a need to specify the cut-off frequency for the filter to pass. The cutoff frequency will set a limit for the filter to allow particular frequencies on images. There are different types of filters to act on an image. In the assignment we have used Gaussian filter to blur the image. The other image is sharpened by simply subtracting the blurred image from its image.
Let us consider a simple 3*3 filter on 5*5 image.We can get blur image by taking convolution multiplication of filter with 3*3 box of the image and assign the sum of the values to the middle pixel of image. Qualitatively, the pixels neighbouring the middle pixel are causing the values to change.
If we take a closer look at the process, we will observe that the pixels at the edge of the image are untouched. This problem can be solved by adding additional pixels at the edge of the image. This method is called as padding. Padding can be done in different ways. We can just add zeros at the end of image. The result is blackness at the corner which can be sometimes undesirable. Some other types of padding are replication of the neighbouring pixels called as replication.Or replicating the opposite edge pixels called as symmetric padding. If we summarize all the previous points we can form an hybrid image. Following steps need to be taken for creating hybrid images:
The steps can be used to get a hybrid image from the given two images.
There are two code snippets given below. One is the my_filter function to filter the images sent to it. Second is the given hybrid image function. Here the hybrid image forms when the cut-off frequency is set to 4.
The third and forth for loop does the operation of iterating as well as creating the box for image to multiply.
%my_filter code
imshow(image);
imwrite(image, 'image_1.jpg', 'quality', 95);
[i,j]=size(filter);
pad_height=double(int8(floor((i/2))));
pad_width=double(int8(floor((j/2))));
padsize=[pad_height,pad_width];
padded_image = padarray(image,padsize,'replicate');
[m,n,p]=size(image);
imshow(padded_image);
imwrite(padded_image, 'padded_image.jpg', 'quality', 95);
output=zeros;
for z=1:3
for x=pad_height+1:m+pad_height
for y=pad_width+1:n+pad_width
temp=0;
for a=-(pad_height):(pad_height)
for b=-(pad_width):(pad_width)
temp=temp+(padded_image(x+a,y+b,z)*filter((pad_height+1+a),(pad_width+1+b)));
end
end
output(x-pad_height,y-pad_width,z)=temp;
end
end
end
imshow(output);
end
%Hybrid image
image1 = im2single(imread('../data/dog.bmp')); %blur
image2 = im2single(imread('../data/cat.bmp')); %sharp
cutoff_frequency = 4;
filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);
image3=my_imfilter(image1,filter);
image3=my_imfilter(image3,filter');
imshow(image3)
imwrite(image3, 'blurred_image.jpg', 'quality', 95);
low_frequencies = image3;
image4=my_imfilter(image2,filter);
image4=my_imfilter(image4,filter');
imshow(image4)
imwrite(image4, 'blurred_image.jpg', 'quality', 95);
high_frequencies =image2 - image4;
imshow(high_frequencies)
imwrite(high_frequencies+0.5, 'sharp_image.jpg', 'quality', 95);
The above images are the images taken while creating hybrid of cat and dog.