필터 지우기
필터 지우기

Image Processing Downloading Images for GUI

조회 수: 1 (최근 30일)
shiffraw dagnechaw
shiffraw dagnechaw 2018년 8월 14일
답변: Jan 2018년 8월 14일
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
Rik
Rik 2018년 8월 14일
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 2018년 8월 14일
imshow( a, 'parent', handles.image_ax )
is better though too to give an explicit parent.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
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.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by