【问题标题】:Making histogram bins uniform - MATLAB使直方图箱统一 - MATLAB
【发布时间】:2018-06-16 05:50:44
【问题描述】:

我一直在从事与 MATLAB 中的图像分析相关的项目。其中一部分需要我创建多组直方图来比较我为图像计算的 GCLM 系数值的分布。

我正在使用 PH2 数据库,共有 200 张图像(按诊断分为三个类别,分别为 80、80、40 张)。我制作了显示每个诊断分布的直方图,我还想覆盖直方图以显示分布的比较情况。这是我正在使用的代码:

    % DECOMP MAX
    figure
    for k=1:4
        subplot(2,2,1)
            h0 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 0,k),10);
            h0.FaceColor = 'green';
            title('Typical')
        subplot(2,2,2)
            h1 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 1,k),10);
            h1.FaceColor = 'yellow';
            title('Atypical')
        subplot(2,2,3)
            h2 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 2,k),10);
            h2.FaceColor = 'red';
            title('Melanoma')
        subplot(2,2,4)
            h0 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 0,k),10);
            hold on
            h1 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 1,k),10);
            h2 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 2,k),10);
            h0.FaceColor = 'green';
            h1.FaceColor = 'yellow';
            h2.FaceColor = 'red';
            title('Overlayed')
        suptitle(names_gclm{:,k})
        fname = sprintf('maxdecomp%d', k);
        set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
        saveas(gcf,fname,'png')
        close all
    end

我的问题从覆盖部分开始。尽我所能,我无法让所有三种诊断的垃圾箱看起来都一样。我尝试手动设置 bin 编号以及栏和 bin 宽度。有什么我想念的吗?我还能尝试什么?我很感激任何建议,因为我已经不知所措了。

这是两个示例图像 - 如您所见,黑色素瘤直方图在第一个中看起来与其他图像完全不同。在第二个中,每个组看起来都不同,因此无法比较分布。

【问题讨论】:

  • 当您说您希望 bin 统一时,您的意思是 histogram equalization 还是您希望 bin 具有统一的间距,即每个 bin 具有相同的宽度?
  • 如果你能发布一个示例输出图像并描述它的问题可能会更容易。
  • @jodag - 我用图片编辑了帖子。我希望我的问题现在更有意义!
  • 您是否尝试过指定 bin edges 而不是每个直方图中的 bin 数量?

标签: matlab image-processing statistics histogram


【解决方案1】:

问题是你需要明确地define the bin edges。您只是告诉直方图函数您需要 10 个 bin。这会导致数据的最小值和最大值的间距一致,如果每个数据集具有不同的界限,则这是不希望的。相反,明确定义 bin 边缘如下...

% DECOMP MAX
figure
for k=1:4
    % determine bin edges
    edge_min = min(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 0 | diagn.ClinicalDiagnosis == 1 | diagn.ClinicalDiagnosis == 2,k))
    edge_max = max(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 0 | diagn.ClinicalDiagnosis == 1 | diagn.ClinicalDiagnosis == 2,k))
    edges = linspace(edge_min, edge_max, 10+1);

    subplot(2,2,1)
        h0 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 0,k),edges);
        h0.FaceColor = 'green';
        title('Typical')
    subplot(2,2,2)
        h1 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 1,k),edges);
        h1.FaceColor = 'yellow';
        title('Atypical')
    subplot(2,2,3)
        h2 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 2,k),edges);
        h2.FaceColor = 'red';
        title('Melanoma')
    subplot(2,2,4)
        h0 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 0,k),edges);
        hold on
        h1 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 1,k),edges);
        h2 = histogram(gclm_decomp_max_p(diagn.ClinicalDiagnosis == 2,k),edges);
        h0.FaceColor = 'green';
        h1.FaceColor = 'yellow';
        h2.FaceColor = 'red';
        title('Overlayed')
        % set plot limits to bin bounds
        xlim([edge_min edge_max]);
        ax = axis();
    % make sure all the axis have same limits
    subplot(2,2,1);
        axis(ax);
    subplot(2,2,2);
        axis(ax);
    subplot(2,2,3);
        axis(ax);

    suptitle(names_gclm{:,k})
    fname = sprintf('maxdecomp%d', k);
    set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
    saveas(gcf,fname,'png')
    close all
end

编辑:更新了完整的解决方案。

【讨论】:

  • 我知道这样发布 cmets 不太符合礼仪,但我想表达我的感激之情 - 这就像一个魅力!非常感谢,非常感谢。
猜你喜欢
  • 2015-05-15
  • 2016-02-21
  • 2021-10-29
  • 1970-01-01
  • 2014-02-21
  • 2013-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多