Code for loading an image question.

3 次查看(过去 30 天)
Hi everyone,
I have this code for loading an image from the current directory. I can't see anything wrong with it but when I try and load an image from the list it just doesn't seem to display. Could someone quickly check over it and see where I have gone wrong? Sorry, new to MATLAB.
Thanks for your time everyone.
  1 个评论
Luke
Luke 2013-4-20
编辑:Walter Roberson 2013-4-20
function [] = GUI_25()
D = dir('*.jpg');
S.NAM = {D(:).name};
S.fh = figure('units','pixels','position',[450 450 400 200],'menubar','none','name','Verify Password.','resize','off','numbertitle','off','name','GUI_25');
S.ls = uicontrol('style','list',...
'units','pix',...
'position',[10 60 380 120],...
'backgroundcolor','w',...
'string',S.NAM,...
'HorizontalAlign','left');
S.pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 380 40],...
'backgroundcolor','w',...
'HorizontalAlign','left',...
'string','Load Image',...
'fontsize',14,'fontweight','bold',...
'callback',{@pb_call,S});
function [] = pb_call(varargin)
S = varargin{3};
L = get(S.ls,{'string';'value'});
try
L = L{1}{L{2}};
X = imread(L);
str = [L(1:end-4),'_',strrep(datestr(now,'HH:MM:SS'),':','_')];
assignin('base',str,X)
catch
fprintf('\t\t%s\n','No file selected, or read error.')
end

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-4-20
You read the image and assign it to a variable in the base workspace, but you do not have any image() or imshow() call to display the image.
  1 个评论
Walter Roberson
Walter Roberson 2013-4-20
Note: using a dynamic variable name is not a good idea. How is the rest of your program going to know where to look to find the variable with the name you calculate in "str" ?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by