0

I am kind of new to Matlab and trying to implement Local Sauvola Image Thresholding Algorithm. But I am getting a complete white output as result. This is my code;

function sauvola(axFiltered)
global imgGray;
global imgFiltered;
k = 0.5;
R = 128;
n = 5;
imgGray = double(imgGray);

imgFiltered =  colfilt(imgGray, [n,n], 'sliding', @(x) ... 
    (mean(x).*(1+k*(std(x)/R-1))));
if imgGray < imgFiltered
    imgGray = 0;
end
if imgGray >= imgFiltered
        imgGray = 255;
end
axes(axFiltered);
imshow(imgGray);
end

I send lena.jpg as image to process but result image is all blank and completely white. I don't know what is wrong. Also I get an output for this; output

I convert image into gray in another function and it works correctly. I checked that too. Thank you in advance.

Hakan Ali Yasdi
  • 105
  • 1
  • 4
  • 14
  • Check your inputs to the `if` clauses. Looks like you are comparing entire images at once, you probably want to compare one pixel at a time. – mikkola Oct 25 '16 at 10:04
  • Oh okay I will try to wrap them with two for loops and check pixel by pixel then. – Hakan Ali Yasdi Oct 25 '16 at 13:14
  • Don't for -loop them, logical indexing is orders of magnitudes faster in most cases. Replace both if-clauses with single imgGray = imgGray >= imgFiltered; , you'll get a binary matrix with the foreground as 1's. – Tapio Oct 28 '16 at 09:52

0 Answers0