MATLAB: How to insert elements in listbox

guiguideimageimage processing

how can i insert list of images into listbox?? I have a folder containg images and i want to insert list of images into the listbox

Best Answer

Hi, Usama.
Maybe you are seeking for something like this?
In the openingfcn
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
files = dir(fullfile(pwd,'Folder01','*.png'));
for x = 1 : length(files)
handles.images{x} = imread(fullfile(pwd,'Folder01',files(x).name));
end
set(handles.listbox1,'string',{files.name});
guidata(hObject, handles);
In the listbox1 callback
function listbox1_Callback(hObject, eventdata, handles)
handles.output = hObject;
index = get(handles.listbox1,'value');
imshow(handles.images{index});
guidata(hObject, handles);
You can also change the image extention by replacing png with another extention
Eq: files = dir(fullfile(pwd,'Folder01','*.jpg'));
And if it is DICOM files
files = dir(fullfile(pwd,'Folder01','*.dcm'));
for x = 1 : length(files)
handles.images{x} = dicomread(fullfile(pwd,'Folder01',files(x).name));
end
I hope this helps.
Related Question