Assignment 2: Part 2:Mask generation for poisson blending using Graphcuts
The objective was to automatically create mask for poisson blending two images using graphcuts. The images were taken from flickr and were used under creative commons license. Aeroplanes were blended into the sky for this assignment. The image of the sky was selected from a database of 50 images taken from flickr using the GIST image descriptor. Specifically, sky & city ,were searched together to get these images. 1.2 Setting up graphcut function The graphcut algorithm used in this project was the Max-flow min-cut algorithm taken from here. This implements Boykov-Kolmogorov algorithm. The files can be downloaded from here. As these files are written in C/C++, a MATLAB wrapper was used. The wrapper can be downloaded from here. This site has plenty of description of how to setup the graphcut algorithm. 1.3 Algorithm & Implementation details The image was modelled as a graph and graphcut algorithm was used to extract the object. Then the output of graphcut was converted into mask to further use in poisson blending. 1.3.1 Image selection using GIST :I have created a reference imageset of 10 images of sky-city under the folder 'city'. Using these 'ideal' images I computed the centroid of their GIST descriptors.This centroid is used as a reference to select a proper image from dataset of 50 images. Euclidean distance is used to measure the similarity of the descriptors with the reference. The user can input a number n to get the best n matches and these are processed to get the max-flow. The image having maximum of the max-flow from n images taken is treated as the best image. 1.3.2 Image Positioning :The image of city-sky and aeroplane hence obtained are resized and aligned. The target image (city-sky image) is assumed to have upper half as sky. The target image is divided into 6 equal parts. The aeroplane image ( also called as source) is aligned and resized to fit the centre upper block of target image. 1.3.3 Mask creation using graphcutsThe source image was converted into a 4 connected graph using the function in the wrapper. A rough mask is assumed to be provided initially which separates the background and the foreground. Using joint histograms RGB channels ( multiply individual probability,ie, Joint P =Pb*Pr*Pg ), probability is found out for a pixel to belong to foreground and background. The histograms are smoothed using a gaussian filter to get a smoother pdf.
1.4 Result Images | ||
Download the zip file and run the cutBlend.m file.