Can't drag rectangle object in GUI axis for large images

1 view (last 30 days)
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 512x512 pixels (approximately), however for larger images (I tried 600x600 and 1024x1024) 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!

Accepted Answer

Ben11
Ben11 on 11 Jun 2014
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.

More Answers (1)

Image Analyst
Image Analyst on 10 Jun 2014
Why are you constraining the rectangle? I never do that. Here, try this code:
hBox = imrect;
roiPosition = wait(hBox); % Wait for user to double-click
roiPosition % Display in command window.
% Get box coordinates so we can crop a portion out of the full sized image.
xCoords = [roiPosition(1), roiPosition(1)+roiPosition(3), roiPosition(1)+roiPosition(3), roiPosition(1), roiPosition(1)];
yCoords = [roiPosition(2), roiPosition(2), roiPosition(2)+roiPosition(4), roiPosition(2)+roiPosition(4), roiPosition(2)];
croppingRectangle = roiPosition;
You can use rbbox() if you want but it finishes immediately. You'd have to use questdlg() to ask them if the box is ok or if they made a mistake and need to try again.
  3 Comments
Image Analyst
Image Analyst on 11 Jun 2014
I've never had that problem. Maybe try adjusting your mouse's double click speed. Or else right click and say "Copy Mask".

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!