Problem with imrect and position vector returned.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Something very strange is happening. Im using imrect to get a user defined ROI from an image (taken from an axes on a GUIDE GUI).
axes(handles.axes4);
Orig=getimage(handles.axes4);
val=get(handles.checkbox13,'Value');
if val==1
position=getappdata(0,'pos');
rectangle('Position',position,'EdgeColor','y')
drawnow;
else
warndlg('Select a box around single object. Try to centre around the Object','Template Matching','modal')
h=imrect
position=wait(h);
setappdata(0,'pos',position);
position
delete(h)
end
Orig=double(imcrop(Orig,position));
For testing, I have the checkbox13 unchecked so the code executes the "else" part.
The warning dialog appears, the blue imrect feature appears and it does indeed create the cropped image.
However, if the checkbox13 is checked, their is an error that "position" is wrong.
To check this, I removed the semi colon for h=imrect & position in the else part of the loop and unchecked the checkbox so the code executed this part. This is what the output is in the command window
h =
0×0 imrect array with properties:
Deletable
position =
[]
This suggests that "position" hasn't been obtained yet the imcrop works correctly. not sure whats going on.
Thanks for any help. Jason
1 Kommentar
Akzeptierte Antwort
Adam
am 10 Mär. 2017
I'm not really sure which 'wait' function is being called there. I don't see one in the documentation that takes an imrect as argument.
You shouldn't need the wait though. imrect blocks program execution anyway until the user draws the rectangle so
h=imrect;
position = getPosition( h )
should work fine.
3 Kommentare
Adam
am 10 Mär. 2017
Ah yes, I missed looking in the obvious place, at the methods of imrect itself. It seems to work fine for me without wait, but obviously that method works fine too.
warndlg with a modal window will block command line input, but will not block program execution though so I imagine that its blocking tangles with that of the wait on imrect in some way.
e.g. if you try the following on command line:
warndlg('This is a warning','Template Matching','modal'); disp( 'finished' )
you will notice that 'finished' appears straight away after the warning dialog is created and does not wait for you to close the dialog, even though you cannot interact with the command line until you have closed it.
Weitere Antworten (1)
Image Analyst
am 10 Mär. 2017
Jason, if you're executing this code:
if val==1
position=getappdata(0,'pos');
then you must have previously loaded pos in to appdata with setappdata(). I'm betting that you have not done this yet. So you first have to do the "else" part before you can do the "if" part or else "pos" will not have been saved and you won't be able to use getappdata() to get it.
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!