Image Processing Downloading Images for GUI

5 vues (au cours des 30 derniers jours)
shiffraw dagnechaw
shiffraw dagnechaw le 14 Août 2018
Réponse apportée : Jan le 14 Août 2018
I'm learning to create GUI's for image processing. I found a youtube video that demonstrates what I need to know, but I'm having an issue. I created a push button ( that I've titled import image) and upon clicking the image a window pops up for me to choose the file (image) that I would like to show up on the GUI plot. When I try choosing a file (image) an error message pops up. The error message states: Reference to non-existent field 'image_ax'. How do I know what to use instead of 'image_ax'? I simply copied that part from the video. I pasted my code below
a = uigetfile() filename = a; setappdata(0,'filename',filename); a = imread(a); axes(handles.image_ax); imshow(a); setappdata(0,'a',a) setappdata(0,'filename',a); plot(handles.image_ax,'a');
  3 commentaires
Rik
Rik le 14 Août 2018
The imshow command doesn't support a target, so the call to axes makes sure that the axes object in your GUI is the current axis. To use this code, you must have already created an axes object and saved the handle to handles.image_ax. You should have a call to guidata somewhere to load the handles struct, or have the handle available using another method (like e.g. with getappdata).
Adam
Adam le 14 Août 2018
imshow( a, 'parent', handles.image_ax )
is better though too to give an explicit parent.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 14 Août 2018
The usage of "a" is confusing in your code:
% Your code:
a = uigetfile();
filename = a;
setappdata(0,'filename',filename);
a = imread(a);
axes(handles.image_ax);
imshow(a);
setappdata(0,'a',a)
setappdata(0,'filename',a);
plot(handles.image_ax,'a');
Storing variables in the root's application data is a bad idea at all, because it suffers from the same problems as global variables. Here "a" and "filename" are mixed and store repeatedly. A cleaner version, if there is really a good reason to store the file name globally:
[FileName, FilePath] = uigetfile();
File = fullfile(FilePath, FileName);
setappdata(0, 'File', File);
img = imread(File);
imshow(a, 'Parent', handles.axes1);
This is not useful - why plotting the letter 'a'?
plot(handles.image_ax,'a');
As mentioned by Adam and Rik already, you have to change "image_ax" to the field name you use. We cannot guess, how it is called, but you can use the debugger. Set a breakpoint in this line and check the contents of the handles struct.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by