Can't open Image. Help me. Please

조회 수: 1 (최근 30일)
Hai Nguyen
Hai Nguyen 2017년 4월 24일
편집: Jan 2017년 4월 24일
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

답변 (2개)

Walter Roberson
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);
  댓글 수: 2
Hai Nguyen
Hai Nguyen 2017년 4월 24일
Thank you. But I can't open it.
Error using LoadImageHai/pb_Callback (line 16) Not enough input arguments. Error while evaluating UIControl Callback
Walter Roberson
Walter Roberson 2017년 4월 24일
Which is line 16?

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


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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by