Can't open Image. Help me. Please
조회 수: 1 (최근 30일)
이전 댓글 표시
function LoadImageGUI()
f = figure;
pb = uicontrol(f,'Style','pushbutton','String','Load Image','Position',[50 30 100 30], 'callback',@pb_Callback);
s = uicontrol(f,'Style','slider','Min',0,'Max',360,'Value',0,'SliderStep',[0.01 0.05],'Position',[180 30 300 30],'callback',@sliderCallback);
ax = axes('Parent',f,'Position',[.15 .25 .7 .7]);
hTxt = uicontrol('Style','text', 'Position',[260 65 20 20], 'String','0');
function pb_Callback(hObj, eventdata, handles)
[filename, pathname] = uigetfile('*.tiff', 'Select a MATLAB code file');
if isequal(filename,0)
disp('User selected Cancel')
else
a=imread(filename, pathname);
info = imfinfo([pathname filename]);
num_images = numel(info);
axes(handles.ax);
imshow(a);
handles.a=a;
set(handles.Z, 'Min', 1);
set(handles.Z, 'Max', num_images);
set(handles.Z, 'Value', 1);
set(handles.Z, 'SliderStep', [1/(num_images-1) , 1/(num_images-1) ]);
handles.lastSliderVal = get(handles.Z,'Value'); % save the current/last slider value
end
guidata(hObject, handles); % Update handles structure
end
end
댓글 수: 0
답변 (2개)
Walter Roberson
2017년 4월 24일
Change
a=imread(filename, pathname);
info = imfinfo([pathname filename]);
to
filepath = fullfile(pathname, filename);
a = imread(filepath);
info = imfinfo(filepath);
Jan
2017년 4월 24일
편집: Jan
2017년 4월 24일
You define the callback as:
pb = uicontrol([...], 'callback',@pb_Callback);
Then it is called as
function pb_Callback(hObject, EventData)
and the 3rd input "handles" is not defined.
Because you have defined the callback as nested function, this 3rd input is not needed. So simply omit it and use ax directly instead of the (undefined!) handles.ax.
handles.Z must fail also. Perhaps you want:
set(s, 'Min', 1, 'Max', num_images, 'Value', 1, ...
'SliderStep', [1/(num_images-1) , 1/(num_images-1) ]);
Summray: The advantages of using the handles struct and netsed functions are mixed completely. Decide for a clear strategy to share variables between callbacks. For further suggestions search for these terms in the forum: "share variables callbacks".
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!