Problem with imrect and position vector returned.
Show older comments
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 Comment
Accepted Answer
More Answers (1)
Image Analyst
on 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.
Categories
Find more on Entering Commands 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!