MATLAB GUI IMAGE PROCESSING FROM LISTBOX

2 views (last 30 days)
I have written a GUI which is using one listbox and two axes. When I click to pushbutton, I can see my folder list in listbox. And after in axes1, I can see images as preview. But I can not use this images for image processing. How can I select an image from listbox for image processeing? Sorry for my bad english.
function menuopenfolder_Callback(hObject, eventdata, handles)
% hObject handle to menuopenfolder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output = hObject;
fn = uigetdir(handles.cdir,'Select directory');
if fn ~= 0
handles.cdir = fn;
img = dir(fullfile(handles.cdir,'*.bmp'));
for x = 1 : length(img)
handles.I{x} = imread(fullfile(handles.cdir,img(x).name));
end
if length(img) ~= 0, set(handles.listbox1,'enable','on');
else, set(handles.listbox1,'enable','off');
end
set(handles.text5,'string',handles.cdir);
set(handles.listbox1,'string',{img.name});
end
guidata(hObject, handles);
--------------------------------
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
handles.output = hObject;
index = get(handles.listbox1,'value');
axes(handles.axes1);
imshow(handles.I{index});
guidata(hObject, handles);
-------------------------------
listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
return
%

Accepted Answer

Image Analyst
Image Analyst on 12 Apr 2015
Get the 'string' property of the listbox to get a list of all the items in the listbox into a cell array. Then get the 'value' property and use it as an index to all the items list to give you the one(s) that are selected.
  1 Comment
MFK
MFK on 12 Apr 2015
Can you help me more please? I couldn't handle with it. Can you give me an example?

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE 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!