MATLAB GUI IMAGE PROCESSING FROM LISTBOX
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2015-4-12
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!