使直方图箱均匀化 - MATLAB

时间:2018-01-06 17:51:34

标签: matlab image-processing statistics histogram

我一直致力于与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编号以及bar和bin宽度。有什么我想念的吗?我还能尝试什么?在我的智慧结束时,我会感激任何建议。

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

1 个答案:

答案 0 :(得分:1)

问题是您需要明确define the bin edges。你只是告诉直方图功能你想要10个箱子。这导致与数据的最小值和最大值的均匀间隔,如果每个数据集具有不同的边界,则这是不期望的。相反,明确定义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

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