【发布时间】:2015-05-03 12:45:38
【问题描述】:
下面是我为“按钮 1”设置的代码,它允许您浏览目录中的某个图像,一旦您选择了一个图像,您就可以在 GUI 上显示它:
% --- 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)
%% Initial Method
[filename pathname] = uigetfile({'*.bmp';'*.jpg'},'File Selector');
handles.MyImage = strcat(pathname, filename);
axes(handles.axes1);
imshow(handles.MyImage)
set(handles.edit1,'string',filename);
set(handles.edit2,'string',handles.MyImage);
%save the updated handles object
guidata(hObject,handles);
使用另一个按钮,我希望绘制灰度图像的直方图,但是直方图看起来完全错误,下面是代码:
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
if isfield(handles,'MyImage')
axes(handles.axes2);
A=histogram(double(handles.MyImage(:)),100);
xlim([0, 255]);
ylim([0, 0.03]);
plot(A)
end
上面有什么我做错了,还是我应该在轴的属性中编辑什么?谁能帮帮我?
【问题讨论】:
-
如果您在问题中包含直方图,或者至少描述它的外观和您的期望,而不是仅仅说它“全错”,您更有可能获得有用的帮助。跨度>
-
它说我需要至少 10 个声望点才能发布图片 :( 我刚接触这个!
-
@SeánMcNeill - 将其发布在某个公共网站上,我们中的一个人会将其放入您的帖子中。
-
应该是
hist,确定吗? -
@nkjt 所以这里是使用 'hist' 的代码:
% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA if isfield(handles,'MyImage') axes(handles.axes2); A=hist(double(handles.MyImage(:)),255); colormap(gray(256)); colorbar off; xlim([0, 255]); ylim([0, 3000]); plot(A) end直方图看起来更好,但仍然不正确。
标签: matlab user-interface image-processing plot histogram