function [props, outBW] = PS_roiExtraction_local(temp1,S,T,M,A)
%***********************************************************************
% This function convert grayscale image to binary image and show ROIs > 10
% pixels. Input variable: a grayscale image. Output variable: a black and
% white image with ROIs >10 pixels in black.
%**************************************************************************
% Modified by Kaichang CHENG in Mar. 3, 2019.
% 1.Change the threshhold of function bwareaopen into 8.
%**************************************************************************
% Modified by Kaichang CHENG in Mar. 27, 2019.
% 1.Change the threshhold of function bwareaopen into 10.
%**************************************************************************
% Modified by Kaichang CHENG in Dec. 13, 2019.
% 1.Use the optimized Sauvola method to extract ROIs.
%**************************************************************************
tempImage = temp1;
%tempBinary = sauvola(tempImage, ceil(size(tempImage)/5));%[3 3] 0.34
%tempBinary = sauvola(tempImage, [S S], T);
tempBinary = sauvola_plankton(tempImage, [S S], T);
%tempBinary = sauvola(tempImage, ceil(size(tempImage)/30), 0.05);
%tempBinary = imcomplement(tempBinary);
tempBW1 = imfill(tempBinary,'holes');
%figure,imshow(tempBW1)
se = strel('disk',M);
closeBW = imclose(tempBW1,se);
outBW = bwareaopen(closeBW, A);

%outBW = bwareaopen(closeBW, 8);
%imshow(outBW, 'initialmagnification', 'fit');
props = regionprops(outBW, 'boundingbox');
end