-1

我需要对已经通过同态滤波器的图像应用阈值。如何确定图像的阈值?

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

我使用的阈值化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

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

+0

放一个断点并检查'thres'是什么。 (检查后告诉我们)。 –

+0

@TonyTannous,thres = 181; – anonymous

+0

如果后者不是内置函数,你可以添加'steve_homo_filter'和'brensen'的代码吗? –

回答

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之间。