Image opening on the wrong axes in a Matlab GUI

16 次查看(过去 30 天)
I have a Matlab GUI window that contains three axes. I have added a callback that allows the user to select an image file to be opened so that a region of interest can be selected. The problem that arises is that the image opens in the wrong axis. I have fixed this by specifying the axes for the image to open in. Another problem arose however; Errors arise stating that for the roipoly command, Matlab expects the image to be open in the current figure. I attempted to reconcile this by using the figure command. This generated an error stating that figure is in use by another object. I then made figure the parent axis for the image. When I did this, the figure window does open but there is no image and a series of errors occur:
Error using exist
The first input to exist must be a string.
Error in isdir (line 11)
result = exist(dirpath,'dir') == 7;
Error in hopefully_the_last_window>pushbutton1_Callback (line 118)
if ~isdir(myFolder) % if the directory is not a valid path
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in hopefully_the_last_window (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)hopefully_the_last_window('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Error using imshow>validateParent (line 306)
HAX must be a valid axes handle.
Error in imshow (line 220)
validateParent(specific_args.Parent)
Error in hopefully_the_last_window>pushbutton3_Callback (line 165)
imshow(Image, 'parent', figure); % generate the image in a figure
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in hopefully_the_last_window (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)hopefully_the_last_window('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
The errors that supposedly arise early in the code (in the first 150 lines) did not arise before I set figure as the parent of the image. My question is, is there a way to generate the image in one of the axes in the window and be able to select a ROI? If this is not possible, what might be the cause of the errors with figure?
  1 个评论
Adam
Adam 2017-7-20
The parent of an image must be an axes, not a figure. The axes are parented by a figure and many axes can have the same parent figure.
Also, you should give a better question title since you seem to have sorted out the question that you put in the title already and then ask a totally different question in the body!

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2017-7-20
编辑:Jan 2017-7-20
The description is vague. Better post the relvant code to demonstrate the problem exactly.
You explanations start with a problem you haved solved already. So why do you explain this?
The error message "The first input to exist must be a string." has no relation to the description. The message is clear, but because you did not show how "dirpath" was created, I cannot suggest an improvement.
The next error message means, that you did not provide a valid axes handle to the function. Without seeing the relevanmt part of the code, I cannot see, what you provide instead, but the solution is clear: You have to provide an axes handle.
imshow(Image, 'parent', figure); % generate the image in a figure
No, not a new figure, but an axes, exactly what the message tells you. Preferrably the existing axes you want to display the image in.
Errors arise stating that for the roipoly command, Matlab expects the image to
be open in the current figure
Do not rephrase the message, but post an exact copy of the complete message and the corresponding code.
  3 个评论
Jan
Jan 2017-7-20
The error message is clear again:
ROIPOLY expects a current figure containing an image.
I do not know, why roipoly cannot find the image in the current figure, but I cannot test this also, because I do not have the image processing toolbox. Perhaps roipoly is not the right tool for you, because it expect inputs you cannot offer?
Omitting the absolute path is a bad idea. Better:
Folder = 'C:\Users\c13459232\Documents\MATLAB');
[File, Folder] = uigetfile(Folder, 'Select a file');
Image = imread(fullfile(Folder, File)); % Read image
There is no need to open a folder browser before the file browser, because you can select a folder in the file browser also. Afterwards consider the selected folder.
Jan
Jan 2017-8-10
@Aaron: It would be nice, if you answer questions for clarifications and accept answers, if they solve your problem. Otherwise the ones, who post answers, might get the impression that you do not care.

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by