The function recenter and imrotate work with the binary image bw where the ROI is centred and rotated very well but when i want to center and rotate the ROI of the color image img it doesn't work :( . I couldn't use imtransform to center the region and rotate the image with a given angle -phy

% Ask the user to click the point they want to be at the center.
userPrompt = 'Click the point you want to be at the center';
promptMessage = sprintf('Click the point you want to be at the center,\nor Cancel to abort processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmp(button, 'Cancel')
return;
end
[x, y] = ginput(1)
% Determine the middle of the picture.
middleX = columns/2
middleY = rows/2
deltaX = fix(middleX - x)
deltaY = fix(middleY - y)

I don't think it's beyond you to figure out what the shift needs to be in the two directions. Give it a try. If really you can't figure out how to subtract the desired x position from the starting x position, write back.

Okay - I've edited it for you to let the user click on a point that she wants to move to the center of the image. Show the older comments above to get the edited code. Let me know if that works for you. With circshift, the edge of the image wraps around, which should not be a problem if it's black. If you want the stuff shifted out of the image to be cut off and the stuff shifted in to be black (instead of from the opposite side of the image) then it's an easy adaptation that you can do.

elseif tx<0
if ty>=0
for i=abs(tx)+1 : X
for j=1 : Y-ty
im_trans(i+tx, j+ty) = image(i, j);
end
end
elseif ty<0
for i=abs(tx)+1 : X
for j=abs(ty)+1 : Y
im_trans(i+tx, j+ty) = image(i, j);
end
end
end
end
can you help me to correct it please