Clear Filters
Clear Filters

Placing multiple rectangles using imrect in GUI

7 views (last 30 days)
Hi everyone!
I am new to gui creation in Matlab and have just worked through the simple Gui tutorial.
What I want to do is the following:
load an image -> drag multiple (e.g. 3) rectangles over the roi using imrect with a specific size (e.g. 32x100 px) and then get the coordinates to process the image only in the specified region by an edge detecting algorithm I programmed.
I am loading and displaying the image using a pushbutton
handles.img_in=imread(load_im());
guidata(hObject,handles)
imshow(handles.img_in);
and I know I can draw a rectangle and get the position via another pushbutton
h=imrect;
rect=uint16(getPosition(h));
can someone help me with the next step that is fixing the size of the rectangle and how to store the data for every instance I click the button and place a rectangle properly?
Every help is appreciated!
Best Wishes, Chris

Accepted Answer

Image Analyst
Image Analyst on 28 Jan 2013
I don't think you can constrain imrect(), rbbox(), or getrect() to work with fixed size rectangles and not allow the user to change the size of the rectangle. The workaround is to have two scroll bars, one for vertical movement and one for horizontal movement. The slider callbacks will calculate the new position of the box sides and draw it using plot(). Then the user clicks an OK button. In fact I do this for some of my apps.
The alternative is to use dragrect(). I haven't used this before. Here is the description from the help:
Examples
Drag a rectangle that is 50 pixels wide and 100 pixels in height.
waitforbuttonpress
point1 = get(gcf,'CurrentPoint') % button down detected
rect = [point1(1,1) point1(1,2) 50 100]
[r2] = dragrect(rect)
Tips
dragrect returns immediately if a mousebutton is not currently pressed. Use dragrect ina ButtonDownFcn, or from the command line in conjunctionwith waitforbuttonpress, to ensure that the mousebutton is down when dragrect is called. dragrect returnswhen you release the mouse button.
If the drag ends over a figure window, the positions of therectangles are returned in that figure's coordinate system. If thedrag ends over a part of the screen not contained within a figurewindow, the rectangles are returned in the coordinate system of thefigure over which the drag began.
Note: You cannot use normalized figure units with dragrect.
  6 Comments
Image Analyst
Image Analyst on 28 Jan 2013
I haven't used it yet. But a common problem is confusing x,y with row,column. The order is reversed: x,y = column,row, not row,column. Could that be the problem?
Christoph
Christoph on 31 Jan 2013
actually it was my mistake because I segmented the image in a wrong way previously!
Thank you for helping it works quite okay now! :)

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!