MATLAB GUI IMAGE PROCESSING FROM LISTBOX
2 views (last 30 days)
Show older comments
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
%
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
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!