function IMBw = LocalOtsuThresh( IMGray, NW )
[M N] = size( IMGray );
IMBw = zeros(M, N);
if nargin < 2
NW = 4;
end
for m = 1:NW
for n = 1:NW
IMTmp = uint8(IMGray( 1+(m-1)*floor(M/NW):m*floor(M/NW),...
1+(n-1)*floor(N/NW):n*floor(N/NW) ));
IMTmpBw = im2bw( IMTmp, graythresh( IMTmp ) );
IMBw( 1+(m-1)*floor(M/NW):m*floor(M/NW),...
1+(n-1)*floor(N/NW):n*floor(N/NW) ) = IMTmpBw;
end
end
NW defines the number of subimages. Default is 4. So in default case the gray level image will be divided into 16 subimages.