【问题标题】:The histogram of my greyscale image plotted on 'axes' in my matlab gui doesn't look like it should?在我的 matlab gui 中绘制在“轴”上的灰度图像的直方图看起来不像应该的那样?
【发布时间】: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


【解决方案1】:

hist 可以返回两个输出。你需要他们两个在这里。

A = hist(X,n);
plot(A);

这将在1:nA 的长度)的 x 轴上绘制 A。因此,如果您使用 100 个 bin 创建绘图,则绘图等效值为 plot(1:100,A)。更改 xlim 不会影响这一点 - 只有您正在查看的部分情节。

hist 的第二个输出返回 hist 使用的 bin 中心(如果 n 是单个数字,则它们应该均匀分布)。

[A,B] = hist(X,n);

如果您随后进行绘图,例如bar(B,A)plot(B,A),你应该得到正确的输出。

顺便说一句,如果您有权访问该工具箱,则可能需要查看 imhist 的图像。

【讨论】:

  • 是的,我有图像处理工具箱,因此我现在正在研究 imhist。我已将代码更改如下,@ 987654334@ .... 但是仍然出现错误,使用“handles.MyImage”作为从上一个按钮保存的 gui 数据是否有问题?还是您认为问题在于具有 imhist 情节的正确属性??
猜你喜欢
  • 1970-01-01
  • 2019-06-01
  • 2015-10-08
  • 2012-05-26
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 2013-07-15
相关资源
最近更新 更多