To split the color region to the center of the image, I tried to do this but I get a binary image img2 like I2 although img is a color image :(
r = recentre(img(:,:,1),barx,bary);
g = recentre(img(:,:,2),barx,bary);
b = recentre(img(:,:,3),barx,bary);
img2 = cat(3, r, g, b);