I need to apply thresholding to an image which has already gone through a homomorphic filter.
My threshold value must be the mean + standard-deviation of image intensity.
I used the thresholding code by Jan Motl as follows:
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
I used the homomorphic filter code from Steve Eddins as follows,
clear_all();
I = gray_imread('cameraman.png');
I = steve_homo_filter(I);
Ithres = bernsen_thres(I);
imshowpair(I, Ithres, 'montage')
But the output is totally black,
What should I do to fix this?
Okay. I solved the problem.
There were two issues,
Intensities of the output of the homomorphic filter were not between 0 and 1. I fixed that by applying
mat2gray()
.Output of
thres_val()
was 181 in this case. That value was divided by 255 in order to bring it between 0 and 1.