I'm trying to implement various binarization algorithms to the image shown:
Here's the code:
clc; clear; x=imread('n2.jpg'); %load original image
% Now we resize the images so that computational work becomes easier later onwards for us.
size(x); x=imresize(x,[500 800]); figure; imshow(x); title('original image'); z=rgb2hsv(x); %extract the value part of hsv plane v=z(:,:,3); v=imadjust(v);
%now we find the mean and standard deviation required for niblack and %sauvola algorithms
m = mean(v(:)) s=std(v(:)) k=-.4; value=m+ k*s; temp=v;
% implementing niblack thresholding algorithm:
for p=1:1:500 for q=1:1:800 pixel=temp(p,q); if(pixel>value) temp(p,q)=1; else temp(p,q)=0; end end end figure; imshow(temp); title('result by niblack'); k=kittlerMet(g); figure; imshow(k); title('result by kittlerMet');
% implementing sauvola thresholding algorithm:
val2=m*(1+.1*((s/128)-1)); t2=v; for p=1:1:500 for q=1:1:800 pixel=t2(p,q); if(pixel>value) t2(p,q)=1; else t2(p,q)=0; end end
figure; imshow(t2); title('result by sauvola');
The results I obtained are as shown:
As you can see the resultant images are degraded at the darker spots.Could someone please suggest how to optimize my result??