Problem with imrect and position vector returned.

1 vue (au cours des 30 derniers jours)
Jason
Jason le 9 Mar 2017
Commenté : Jason le 10 Mar 2017
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 commentaire
Jason
Jason le 10 Mar 2017
Modifié(e) : Jason le 10 Mar 2017
The issue goes away when I remove the warndlg code:
% warningString=sprintf('Select a box around single object \n Try to centre around the Object')
% warndlg(warningString,'Template Matching','modal')
h = imrect;
position =
262.5620 280.0704 57.6085 51.9606
Why would this be?

Connectez-vous pour commenter.

Réponse acceptée

Adam
Adam le 10 Mar 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 commentaires
Adam
Adam le 10 Mar 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.
Jason
Jason le 10 Mar 2017
Thanks Adam

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 10 Mar 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.
  1 commentaire
Jason
Jason le 10 Mar 2017
Thanks I A.
I have it so by default the checkbox is unchecked and so saves to positions to appdata on the first iteration.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by