niblack 二值化算法源程序 matlab
来源:互联网 发布:手机 淘宝教育 编辑:程序博客网 时间:2024/05/18 02:01
基于matlab的niblack 二值化算法源程序 ,希望对大家有帮助
function imagBW = niblack(imag)
% NIBLACK binarizes a gray scale image 'imag' to a binary image, using
% Niblack algorithm. The noises of the gray scale image are removed.
% Input:
% imag: the gray scale image, with black foreground(0), and white
% background(255).
% Output:
% imagBW: the binary image of the gray scale image 'imag', with
% Niblack algorithm.
% Reference:
% Wayne Niblack. An Introduction to Digital Image Processing. pp: 115.
% 1986. Prentice/Hall International. ISBN: 013 480674 3
tic;
k = -0.2; % the first manual parameter
b = 80; % the second manual parameter, about the width of the square neighborhood
choice = 1; % 1 for pixel-to-pixel computation, 2 for pixel averaging within the square neighborhood for fast computation.
imag = imag( :, :, 1);
[Hei, Wid] = size(imag);
imag = padarray(imag, [b b], 'symmetric', 'both'); % Pad image array
Hei_pad = Hei + 2 * b;
Wid_pad = Wid + 2 * b;
imagBW = false(Hei_pad, Wid_pad);
switch choice
case 1
for i = 1+b : Hei+b
for j = 1+b : Wid+b
upR = i-floor(b/2-1/2);
dnR = i+floor(b/2);
lfC = j-floor(b/2-1/2);
rtC = j+floor(b/2);
m_ij = mean(mean(imag(upR : dnR, lfC : rtC)));
sigma_squared = double(imag(upR : dnR, lfC : rtC)) - m_ij;
sigma_squared = mean(mean(sigma_squared .^2));
sigma = sqrt(sigma_squared);
th_ij = m_ij + k * sigma;
if double(imag(i,j)) > th_ij
imagBW(i,j) = 1;
end
end
end
case 2
for i = 1+b : b : Hei+b
for j = 1+b : b : Wid+b
upR = i-floor(b/2-1/2);
dnR = i+floor(b/2);
lfC = j-floor(b/2-1/2);
rtC = j+floor(b/2);
m_ij = mean(mean(imag(upR : dnR, lfC : rtC)));
sigma_squared = double(imag(upR : dnR, lfC : rtC)) - repmat(m_ij, (dnR-upR+1), (rtC-lfC+1));
sigma_squared = sigma_squared .^ 2;
sigma_squared = mean(mean(sigma_squared));
sigma = sqrt(sigma_squared);
th_ij = m_ij + k * sigma;
imagBW(upR : dnR, lfC : rtC) = double(imag(upR : dnR, lfC : rtC)) > th_ij;
end
end
otherwise
display('Wrong Choice!');
end
imagBW = imagBW(1+b : Hei+b, 1+b : Wid+b);
% figure, imshow(imagBW), title('Binarized Image');
toc;
- niblack 二值化算法源程序 matlab
- 【二值化】Niblack算法
- Niblack---二值化算法
- 局部二值化算法Niblack OpenCV实现
- 一个matlab遗传算法源程序
- 一个matlab遗传算法源程序
- Niblack和局部均值算法的二值化比较
- MATLAB源程序
- Niblack算法和OTSU算法的实现
- Niblack算法和OTSU算法的实现
- Niblack二值化方法的实现
- Niblack二值化方法的实现
- Niblack算法的快速实现技巧
- Niblack算法的快速實現技巧
- Niblack算法的快速实现技巧
- Niblack算法的快速实现技巧
- 用matlab进行图像二值化源程序
- 带交叉因子的粒子群优化算法matlab源程序
- Action game: Brave.Bob
- 【转】TCP-IP传输层你懂多少
- [Android]aidl命令
- Linux下的getch()函数的改进版
- Ubuntu 11.04 快速配置
- niblack 二值化算法源程序 matlab
- Windows服务编写原理及探讨(转载)
- 谈谈对于企业级系统架构的理解
- 如何把SWF转为PDF文件
- C#获取当前应用程序所在路径
- win7 64位下iis配置小问题
- ubuntu8.04 nfs挂载文件系统设置
- flash 轮询新闻幻灯播放
- 耿然耿后旺 自我介绍