Project 2 (Computer Vision) : Hybrid Images

Overview

The goal of this part of the assignment is to create hybrid images using the approach described in the SIGGRAPH 2006 paper by Oliva, Torralba, and Schyns. Hybrid images are static images that change in interpretation as a function of the viewing distance. The basic idea is that high frequency tends to dominate perception when it is available, but, at a distance, only the low frequency (smooth) part of the signal can be seen. By blending the high frequency portion of one image with the low-frequency portion of another, you get a hybrid image that leads to different interpretations at different distances.


Problem

At first, I try to use Python to do the project. Every step looks fine but the result image is a bit of disturbed. Since the images using the library matplotlib to resize the images, it normalize the images RGB to 0~1. Besides, the order of the color channels are RGB in matplotlib while the order is BGR in OpenCV.  Even though I try to convert the order of color channels between two libraries, openCV seems cannot accept normalized 0~1 color values which is the same with the library Image. Moreover, when I try to save the images dealt by matplotlib, the shape (size) of the images change. Because matplotlib comes from matlib and matlib do not care about pixel and the size of image showing on the screen will change to fit the screen. Therefore, I can not save the image properly and read it again by another library with the original size. Finally, though I got the result of the hybrid image, it looks not good. So, I have to use matlab to do this project.

This is my question and Python code on stackoverflow and github: 

https://stackoverflow.com/questions/48798060/pythonhow-to-use-opencv-to-show-plt-image?noredirect=1#comment84602001_48798060


Steps:

Resize images

Since the sizes of two images may be totally different, we need to resize and rotate the images. In matlab, we can use ginput to get the x,y of two pixels of each image. Here I choose the pixels on the eyes of two images. After that using padarray, imresize and imrotate to resize two images so that they can be aligned properly. We pad it with black (rgb value is 0) because when add two images up, 0 will not effect.






Image Filtering And Hybrid

When low-pass filter one image, I use imgaussfilt. While high-pass filtering another image, I just subtract the Gaussian-filtered image from the original.

function [img] = hybridImage(im1, im2, cutoff_low, cutoff_high)

im11 = imgaussfilt(im1, cutoff_low);
im22 = imgaussfilt(im2, cutoff_high);
im22 = im2 - im22;
img = im11 + im22;
Change the size of the hybrid image to see the difference.


Frequency Magnitude through Fourier Transform


(image after resize)


(image after resize)


(Low frequency)


(High requency)


(Hybrid)

Bell & Whistles

Above hybrid image is based on input two RGB images. Now, I try to use gray images and see the result.

1. Low frequency image (Obama) is a gray image while High frequency (Trump) image is a RGB image.

2. Low frequency image (Obama) is a RGB image while High frequency image (Trump) is a gray image.

3. Both imput images are gray images.


Other results:




Code (matlab):

https://github.com/Sengo-CN/hybrid-image

 

猜你喜欢

转载自blog.csdn.net/sengo_gwu/article/details/79336511