Clear Filters
Clear Filters

how to apply sauvola threshold in subtracting

2 views (last 30 days)
yasmin ismail
yasmin ismail on 31 Jul 2023
Edited: DGM on 2 Aug 2023
How to apply sauvola threshold on image 1 to get the result as shown in 2?

Answers (1)

DGM
DGM on 31 Jul 2023
Edited: DGM on 31 Jul 2023
No thresholding has been applied to that image. It's had a slight gamma adjustment and then it's been inverted.
A = imread('1reg.png'); % original
B = imread('2reg.png'); % modified
% recreate B from A
B2 = 1.412 - 1.33*im2double(A).^0.456;
B2 = im2uint8(B2);
% compare the two
imshow([B B2],'border','tight')
Otherwise:
  2 Comments
yasmin ismail
yasmin ismail on 1 Aug 2023
they said they use sauvola for subracting and already I used the file exchange but I got different result
can you explin to me the equation you used B2 = 1.412 - 1.33*im2double(A).^0.456;
DGM
DGM on 2 Aug 2023
Edited: DGM on 2 Aug 2023
I don't know what the paper did or what the images mean. I'm not going to pay $30 read the paper. All I know is that there are two images which strongly appear to be related by a simple continuous value transformation. In order to provide substantiation for my suspicion, I registered the two images so that they could be compared.
% these images were manually registered
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1446877/1reg.png');
B = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1446872/2reg.png');
% put both A,B in unit-scale
A = im2double(A);
B = im2double(B);
% find the output values for each input value
% this could probably be simplified, but it doesn't matter here
Asort = unique(A(:));
Bsort = zeros(size(Asort));
for k = 1:numel(Asort)
Bsort(k) = mean(B(A==Asort(k)));
end
% plot the relationship between input and output intensity
plot(Asort,Bsort); hold on
% do a curve fit on the main portion of the TF curve
% ignore junk near zero
x = Asort(14:end);
y = Bsort(14:end);
ff = fit(x,y,'power2') % y = 1.412 - 1.33*x^0.456
ff =
General model Power2: ff(x) = a*x^b+c Coefficients (with 95% confidence bounds): a = -1.328 (-1.362, -1.294) b = 0.4568 (0.4392, 0.4745) c = 1.412 (1.376, 1.447)
% draw the estimated TF curve
xx = linspace(0,1,100);
yy = 1.412 - 1.33*xx.^0.456;
plot(xx,yy)
unitaxes
So the relationship between the given images is largely as suspected. Only near the origin (remember that y is inverted) does the data not fit the trend. Bear in mind that both A and B contain very few pixels in this region.
figure;
imhist(A) % there are only 8 pixels <= 0.1
Given the image source integrity (possibly scanned, compressed, transcoded, re-registered), we can expect that region of the curve to be dominated by errors. While it's possible that this narrow region is a consequence of some thresholding operation, it's reasonable to assume that it's just noise. If it is a piecewise curve, it's hard to back-calculate what it might be based on the available information.
yy = min(yy,0.9); % maybe?
figure
plot(Asort,Bsort); hold on
plot(xx,yy)
unitaxes

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!