0

How to apply Sauvola local image thresholding by MATLAB? I downloded the File Exchange contribution:

https://www.mathworks.com/matlabcentral/fileexchange/40266-sauvola-local-image-thresholding?tab=reviews%2F2147193

But I don’t know how to use it? Can anyone excplain how to use Sauvola and write the code use for it to find threshold the code available in MATLAB as following

function output=sauvola(image, varargin)
% Initialization
numvarargs = length(varargin);      % only want 3 optional inputs at most
if numvarargs > 3
    error('myfuns:somefun2Alt:TooManyInputs', ...
    'Possible parameters are: (image, [m n], threshold, padding)');
end

optargs = {[3 3] 0.34 'replicate'}; % set defaults

optargs(1:numvarargs) = varargin;   % use memorable variable names
[window, k, padding] = optargs{:};

if ndims(image) ~= 2
    error('The input image must be a two-dimensional array.');
end

% Convert to double
image = double(image);

% Mean value
mean = averagefilter(image, window, padding);

% Standard deviation
meanSquare = averagefilter(image.^2, window, padding);
deviation = (meanSquare - mean.^2).^0.5;

% Sauvola
R = max(deviation(:));
threshold = mean.*(1 + k * (deviation / R-1));
output = (image > threshold);
end
 I=imread('blir.jpg');
 % Mean value
 mean = averagefilter(image, window, padding);

% Standard deviation
meanSquare = averagefilter(image.^2, window, padding);
deviation = (meanSquare - mean.^2).^0.5;

% Sauvola
R = max(deviation(:));
threshold = mean.*(1 + k * (deviation / R-1));
output = (image > threshold);

How to use them?

output=sauvola(I, varargin)
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
yasmin
  • 11
  • 1
  • 1
    “Can someone write code for me” is kind of a rude thing to ask. It seems this function just needs an image as input. Did you try that? – Cris Luengo Jul 08 '23 at 20:42
  • I didnt mean to write code, Exchange file of Sauvola is already in matlab and I attached it if you read my question carefully, but the problem is appearing of error when I enter the image – yasmin Jul 09 '23 at 18:53

0 Answers0