【问题标题】:Plotting an image (.tif) and a contour in one axes on GUI matlab在 GUI matlab 上的一个轴上绘制图像(.tif)和轮廓
【发布时间】:2013-06-10 09:00:46
【问题描述】:

我正在开发一个能够显示图像和与后者图像相关的数据的 GUI。

我有一个 x,y 图像和一个函数 f(x,y)(这是一个轮廓),我想使用轴对象在一个图中同时显示图像和轮廓。

这就是我在轴上显示图像的方式:

function aff_toto_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin

imshow(handles.im_ref,'parent',handles.axes1);

现在我得到一个轮廓矩阵:

[handles.c,handles.h] = contour(handles.coor_y,handles.coor_x,handles.fun,handles.vec_iso);

我想在图像本身上绘制这些轮廓线,handles.axes1. 有人知道吗?

感谢大家阅读本文。

编辑: 现在我只是想在我的图片上绘制一些随机正弦。我试过了

imagesc(handles.im_ref,'parent',handles.axes1);

hold(handles.axes1,'on');
plot(handles.axes1,handles.coor_x,sin(handles.coor_x));
hold off;

显示图片但情节仍然不可见。

【问题讨论】:

  • 是的,这是我正在尝试做的一个例子,谢谢它非常相关。但我也在使用 GUI,然后我不知道如何使用这个示例(例如,我不明白保持在 GUI 中的工作方式)。如果我不能用你给我的东西解决我的问题,我会回到这里。
  • 要检查您是否在图像上绘制了白色背景,您可以尝试:set(handles.axes1,'color','none')sin 绘图之后。那应该给你一个透明的背景
  • @Schorsch 使用set(handles.axes1,'color','none') 和你给我的例子我设法做到了。非常感谢。
  • 您可以回答自己的问题。这样一来,您就可以帮助以后访问该站点的处于您的情况的其他人。解释你做了什么并提供你的最终代码。您也可以接受自己的答案。

标签: matlab matlab-guide


【解决方案1】:

我最终发现了我的问题所在。使用 gui 对象 hold 函数必须以不同的方式使用。如下所示,您可以指定对象保持是否有效。 contour 函数也是如此。可以声明Parent 属性(可以是轴)。

function aff_toto_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin

imagesc(handles.im_ref,'parent',handles.axes1);

hold(handles.axes1,'on');
set(handles.axes1,'color','none');

[handles.c,handles.h] = contour(handles.coor_y,handles.coor_x,handles.ch_tr,handles.vec_iso,'Parent',handles.axes1);
hold(handles.axes1,'off');

使用此代码,我能够解决我的问题。另请参阅this page,以了解有关在随机图片上绘制随机曲线问题的更多信息(例如,此处讨论了图像翻转问题)。

【讨论】:

    猜你喜欢
    • 2020-11-24
    • 2012-06-24
    • 2014-03-20
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2012-11-06
    • 2017-10-07
    相关资源
    最近更新 更多