MATLAB: Can’t drag rectangle object in GUI axis for large images

axisguiimage displayImage Processing Toolbox

I'm making a GUI (with GUIDE) in which there is an axis used to display image sequences. In order to let the user select a region of interest in the sequence I'm using 'imrect'. The problem is the following: everything goes fine when images are smaller than 512×512 pixels (approximately), however for larger images (I tried 600×600 and 1024×1024) the rectangle does appear, I can change its size but I can't drag it around. I though it had to be with axis units so I changed the property from 'pixels' to 'normalized' and use normalized coordinates, but it does not work.
Here is my code to create the rectangle and restrain its movement to the axis limits:
hROI = imrect(hVideo,[Width/4 Height/4 Width/2 Height/2]; % Arbitrary size and position of the rectangle, centered on the image.
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(hROI,fcn);
I did not try using 'rbbox' for simplicity purposes, but maybe that was a poor choice. When I perform the same operation on those large images outside the GUI it works well, so I guess the problem lies in the axis properties or something, but I can't get my finger on it.
Any hints are welcome. Thanks!

Best Answer

I found a workaround to the problem; it has to do with the call to imshow just before calling imrect.
In imshow I have to specify "XData" and 'YData" as the parameters corresponding to the axis limits. Example:
imshow(Movie{frame},'parent',handles.axes1_Video,'XData',get(gca,'XLim'),'YData',get(gca,'YLim'));
It works for images up to 1024x1024.