function im_cc = CS4640_moving_cc(im1,im2)
%

im1r(:,:,1) = imresize(im1(:,:,1),[270,480]);
im1r(:,:,2) = imresize(im1(:,:,2),[270,480]);
im1r(:,:,3) = imresize(im1(:,:,3),[270,480]);
im2r(:,:,1) = imresize(im2(:,:,1),[270,480]);
im2r(:,:,2) = imresize(im2(:,:,2),[270,480]);
im2r(:,:,3) = imresize(im2(:,:,3),[270,480]);

imd = CS4640_im_dist(double(im1r),double(im2r));
im_cc = bwlabel(imd>max(max(imd))/3);
return

imdc = bwmorph(imd>30,'clean');
mask = imd>max(max(imd))/2;
mask = bwmorph(mask,'dilate',12);
mask = bwmorph(mask,'erode',12);
[rows,cols] = find(mask);
r_min = min(rows);
r_max = max(rows);
c_min = min(cols);
c_max = max(cols);
mask = 0*mask;
mask(r_min:r_min+1,c_min:c_max) = 1;
mask(r_max-1:r_max,c_min:c_max) = 1;
mask(r_min:r_max,c_min:c_min+1) = 1;
mask(r_min:r_max,c_max-1:c_max) = 1;
[rows,cols] = find(mask);
row = mean(rows);
col = mean(cols);

return

[M,N] = size(imdc);

for r = 1:M
    r_min = max(1,r-floor(LEN1/2));
    r_max = min(M,r+floor(LEN1/2));
    for c = 1:N
        c_min = max(1,c-floor(LEN2/2));
        c_max = min(M,c+floor(LEN2/2));
        s = sum(sum(imdc(r_min:r_max,c_min:c_max)));
        if s<AREA_MIN
            imdc(r,c) = 0;
        end
    end
end


imDE = bwmorph(imdc,'dilate',12);
imDE = bwmorph(imDE,'erode',12);
[rows,cols] = find(imDE);
r_min = min(rows);
r_max = max(rows);
c_min = min(cols);
c_max = max(cols);
row = floor((r_min+r_max)/2);
col = floor((c_min+c_max)/2);

mask = 0*imdc;
mask(r_min:r_min+1,c_min:c_max) = 1;
mask(r_max-1:r_max,c_min:c_max) = 1;
mask(r_min:r_max,c_min:c_min+1) = 1;
mask(r_min:r_max,c_max-1:c_max) = 1;
combo(mat2gray(im2gs),mask);
