Can't open Image. Help me. Please
Show older comments
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
Answers (2)
Walter Roberson
on 24 Apr 2017
Change
a=imread(filename, pathname);
info = imfinfo([pathname filename]);
to
filepath = fullfile(pathname, filename);
a = imread(filepath);
info = imfinfo(filepath);
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".
Categories
Find more on Update figure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!