Image Processing Downloading Images for GUI
조회 수: 3 (최근 30일)
이전 댓글 표시
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
Adam
2018년 8월 14일
imshow( a, 'parent', handles.image_ax )
is better though too to give an explicit parent.
답변 (1개)
Jan
2018년 8월 14일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!