Can't drag rectangle object in GUI axis for large images
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 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 Kommentare
Image Analyst
am 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".
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!