The Co-segmentation problem [1] is where the objective is to segment a similar object from a pair of images. The background in the two images may be arbitrary; therefore, simultaneous segmentation of both images must be performed with a requirement that the appearance of the two sets of foreground pixels in the respective images are consistent. Existing approaches [1, 2] cast this problem as a Markov Random Field (MRF) based segmentation of the image pair with a regularized difference of the two histograms – assuming a Gaussian prior on the foreground appearance [1] or by calculating the sum of squared differences [2]. Both are interesting formulations but lead to difficult optimization problems, due to the presence of the second (histogram difference) term. The model proposed here bypasses measurement of the histogram differences in a direct fashion; we show that this enables obtaining efficient solutions to the underlying optimization model. Our new algorithm is similar to the existing methods in spirit, but differs substantially in that it can be solved to optimality in polynomial time using a maximum flow procedure on an appropriately constructed graph.
References: [1] C. Rother, T. Minka, A. Blake, and V. Kolmogorov. Cosegmentation of image pairs by histogram matching – incorporating a global constraint into MRFs. In Proc. of Conf. on Computer Vision and Pattern Recognition, 2006.
[2] L. Mukherjee, V. Singh, and C. R. Dyer. Half-integrality based algorithms for cosegmentation of images. In Proc. of
Conf. on Computer Vision and Pattern Recognition, 2009.
FUNCTION CALL
./segment -conf seg.conf.imagename imagefilename1 imagefilename2
seg.conf.stone provided with this distribution is setup to run on stone1_128_small.png and stone2_128_small.png, the histogram files (histfile1.raw and histfile2.raw) are created accordingly. Run as
./segment -conf seg.conf.stone ../pairimages/stone1_small_128.png ../pairimages/stone2_small_128.png
FOR INPUT
Before you can run this code on new images you will need the following files:
histsizes.dat (written by the matlab files under histogram_creation_code)
histfile1.raw (histogram of the 1st image, written by the matlab files under histogram_creation_code)
histfile2.raw (histogram of the 2nd image, written by the matlab files under histogram_creation_code)
ses.conf.imagename (this file is the configuration file, contains the path for the histfiles, value of the regularizer lambda, variables called epsilon and numLambdas that are always set to 1, these are internal parameters of the parametric max-flow), the sigma values for smoothness and datacost, the relative influence of the BG (called inflBG) and the number of fg and bg labels and finally these labels (one per line, first specify fg labels in sequence and then bg labels in sequence). These labels are used to set up the data cost for MRF. This configuration file must have seg.conf in the name. See the provided file for an example of what values it should have. To run a simple MRF, (not coseg) set lambda=0, inflBG=1.
FOR OUTPUT
The output is written in the directory output, two file names are created, mask_im1_seg.png and mask_im2_seg.png, which are the segmentation masks of the two images.
To see the mask as a regular binary image in matlab do the following.
im=imread('mask_im1_seg.png');
im=double(2-im./100);
imshow(im)
A sample histogram generation code is provided with this distribution.