如何对图像进行阈值处理?

时间:2017-07-23 22:03:00

标签: matlab image-processing homomorphic-filter image-thresholding

我需要对已经通过同态滤波器的图像应用阈值处理。

我的阈值必须是图像强度的平均值 + 标准偏差

我使用阈值code by Jan Motl如下:

function J = bernsen_thres(I)
    T = thres_val(I);

    J = bernsen(I, [T T],20,'replicate');
end

function T = thres_val(I)
    mn = mean(I(:));
    sd = std(double(I(:)));
    thres = round((mn+sd));

    if(is_odd(thres))
        T = thres;
    else
        T = thres+1;
    end

 function ret = is_odd(val)
    if(mod(val,2) == 0);
        ret = 0;
    else
        ret = 1;
    end

我使用了同形过滤器code from Steve Eddins,如下所示,

clear_all();

I = gray_imread('cameraman.png');
I = steve_homo_filter(I);

Ithres = bernsen_thres(I);

imshowpair(I, Ithres, 'montage')

但是输出完全是黑色的,

enter image description here

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

好。我解决了这个问题。

clear_all();

I = gray_imread('cameraman.png');    

Ihmf = mat2gray(steve_homo_filter(I));

T = thres_val(I)/255

Ithres = Ihmf > T;

imshowpair(Ihmf, Ithres, 'montage');

有两个问题,

  1. 同态滤波器输出的强度不在0和1之间。我通过应用mat2gray()来解决这个问题。

  2. 在这种情况下,thres_val()的输出为181。该值除以255,以使其在0和1之间。

相关问题