【问题标题】:MATLAB: Finding minimum within a selected histogram regionMATLAB:在选定的直方图区域内查找最小值
【发布时间】:2015-08-11 16:57:13
【问题描述】:

所以我在 Matlab 中创建了一个图像直方图,用户可以使用 imrect 来选择所需的区域。

我希望能够从用户选择的区域中找到最小 y 值。

这是我目前所拥有的:

handles.pet_hist_rect = imrect(gca);
[xmin ymin width height] = getPosition(handles.pet_hist_rect);
xdata = get(findobj(gcf,'type','patch'),'xdata');
ydata = get(findobj(gcf,'type','patch'),'ydata');

我不确定如何从 [xmin, xmin+width] 范围内提取最小 y 值(来自 ydata)

提前致谢!

【问题讨论】:

    标签: matlab user-interface histogram


    【解决方案1】:

    我认为您的代码首先没有运行,因为您试图将 getPosition(一个 1x4 数组)的输出分配给另一个数组的单个条目,这不起作用。将其更正为

    position = getPosition(handles.pet_hist_rect);
    

    您现在可以访问 xmin 作为位置 (1),访问 ymin 作为位置 (2) 等等。 现在, ymin = position(2) 已经是您所要求的(y 的最小值),但我不确定,我正在把你带到这里。无需查询图形属性。如果这不是您想要的,您将不得不稍微改写一下这个问题。

    编辑:以下是超级粗略的,应该可以工作,但是如果任何直方图计数为零,则不起作用!

    close all;
    hist(rand(1000, 1));
    handles.pet_hist_rect = imrect(gca);
    position = getPosition(handles.pet_hist_rect);
    xdata = get(findobj(gcf,'type','patch'),'xdata');
    ydata = get(findobj(gcf,'type','patch'),'ydata');
    x = xdata{1};
    x(x < position(1))=0;
    x(x > position(1) + position(3))=0;
    x(x>0) = 1;
    y = ydata{1}(logical(x));
    y(y==0) = NaN;
    m = min(y);
    

    【讨论】:

    • 对不起,我的问题不是很清楚——我不是在寻找整个直方图中的 y 最小值,而是只在直方图的某个区域中寻找。希望现在更有意义
    • 你能发布一个示例直方图吗?
    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 2016-05-31
    • 1970-01-01
    • 2015-10-20
    • 2015-06-05
    相关资源
    最近更新 更多