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