Franta Mráz
Franta Mráz

Reputation: 37

Loading either one or multiple images Matlab GUI

I want to load multiple images in Matlab GUI. Algorithm below:

 % --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename path] = uigetfile('*.jpg','*.png','Chose files to 
load','MultiSelect','on');
 if isequal(filename,0) || isequal(path,0) 
return
end
if iscell(filename)
img = cell(size(filename));
for ii = 1:numel(filename)
img{ii} = imread(fullfile(path,filename{ii}));
end
else
img{1} = imread(fullfile(path,filename));
end
filename = strcat(path,filename);
fullpathname = strcat(path, filename);
set(handles.edit1,'String', fullpathname);
fileID = fopen(strcat(path, filename), 'r');

I also need the directory of an image or images to bee seen text box, but it gives me subsequent error:

Error using imread>parse_inputs (line 457)
The file name or URL argument must be a string.
Error in imread (line 316)
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
Error in untitled>pushbutton1_Callback (line 112)
im = rgb2gray(imread(filename));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in 
@(hObject,eventdata)
untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

Could you please give me a hint, what and how I can customize the algorithm to make it functional?

Upvotes: 1

Views: 39

Answers (1)

Pablo Jeken Rico
Pablo Jeken Rico

Reputation: 579

One reason for the code to fail is that once you merge the filename and the path you miss a / (or \ depending on which OS you are working). Therefore you should use fullfile(path,filename) instead of strcat(path,filename).

Upvotes: 1

Related Questions