Niblack二值化算法是比较简单的局部阈值方法,阈值的计算公式是T = m + k*v,其中m为以该像素点为中心的区域的平均灰度值,v是该区域的标准差,k是一个系数,matlab程序如下: I = imread('card3.bmp'); I = rgb2gray(I); w = 2;% max = 0; min = 0; [m,n] = size(I); T = zeros(m ,n ); % for i = (w + 1):(m - w) for j = (w + 1):(n - w) sum = 0; for k = -w:w for l = -w:w sum = sum + uint32(I(i + k,j + l)); end end average = double(sum) /((2*w+1)*(2*w+1)); s = 0; for k = -w:w for l = -w:w s = s + (uint32(I(i + k,j + l)) - average)*(uint32(I(i + k,j + l)) - average); end end s= sqrt(dou