function alpha = extract_fg(im_in)


if ~exist('im_in')
  addpath('../../../../timeLapseCode/TimeLapseVideo/helpers/mexopencv/mexopencv');
  addpath('../../../../timeLapseCode/TimeLapseVideo/helpers/matting/');
  im_in = double(imread(sprintf('../../aligned_data/mit_martin/0006_001.jpg')))/255;
end


%% Generate trimap by grabCut
[h_orig w_orig c]=size(im_in);
im_in = imresize(im_in, 0.2); 

[h w c]=size(im_in);

trimap_i = zeros(h, w)+ 3;
trimap_i(1:200,1:10) = 0;
trimap_i(1:200,end-10:end) = 0;
trimap_i(70:end, 70:130) = 1; 

import cv.*;
trimap = grabCut(uint8(255*im_in), trimap_i);
fg_mask = (trimap == 1 ) + (trimap == 3) ;


%% Laplacian matting
se = strel('disk', 11);
fg_mask_1 = imerode(fg_mask, se);  
bg_mask_1 = imerode(1-fg_mask, se);

consts_vals = fg_mask_1;
consts_map = fg_mask_1 + bg_mask_1; 

levels_num=1;
active_levels_num=1;
thr_alpha=[];
epsilon=[];
win_size=[];

alpha=solveAlphaC2F(im_in,consts_map,consts_vals,levels_num, ...
                   active_levels_num,thr_alpha,epsilon,win_size);
[fg,bg]=solveFB(im_in,alpha);
alpha = cat(3,alpha, alpha,alpha);
alpha = imresize(alpha, [h_orig w_orig]);

  %% Testing

  %figure;imshow(alpha);
  %new_bg = reconstruct_bg;  
  %test = double(new_bg)/255.*(1-alpha) + alpha.*im_orig; 
  %figure; imshow(test);


