Placing multiple rectangles using imrect in GUI

3 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2013-1-28
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 个评论
Image Analyst
Image Analyst 2013-1-28
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 2013-1-31
actually it was my mistake because I segmented the image in a wrong way previously!
Thank you for helping it works quite okay now! :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by