1 简介
文档图像是以像素形式存贮的, 很难直接操纵 其中的文本内容, 为了识别单个汉字, 必须进行文档 图像分割.本文基于中文文档图像的特征, 提出 了一种基于投影法的文档图像分割算法,,从文档图像的投影出发,根据文档图像水平投影的统计特性,进行灰度值累加,找到每行文字所在坐标;根据文字的竖直投影形状特征,进行竖直方向上的分割,通过对字符图像的分割,实现对整篇文档的分割;对各种字体的文档图像的灰度图进行了试验.结果表明,该算法能够准确地对文档图像进行分割.
2 部分代码
clear;
clc;
close all;
Img = imread('timg.jpg');
GapHeight = 10;
GapWidth = 8;
ImdiSize = 2;
% Img:载入的图像数据
% GapHeight:字符之间的间隔高度
% GapWidth:字符之间的间隔宽度
% ImdiSize:膨胀像素值,与图像大小、分辨率有关
% DrawPic:是否单独输出图像
CharHeight = 10;
CharWidth = 3;
NoiseLevel = 1;
DrawPic = false;
% Img:载入的图像数据
% CharHeight:字符本身的间隔高度
% CharWidth:字符本身的间隔宽度
% NoiseLevel:噪声水平,低于此值视为噪声
% ImdiSize:膨胀像素值,与图像大小、分辨率有关
% DrawPic:是否单独输出图像
b = connect(Img, GapHeight, GapWidth, ImdiSize, DrawPic);
[perpen_locs, horiz_locs] = projection...
(Img, CharHeight, CharWidth, NoiseLevel, ImdiSize, DrawPic);
%在图上按照得到的坐标画线
if DrawPic == false;
figure;
imshow(Img);
title('原图');
figure;
subplot(211);
imshow(Img);
hold on;
for i = 1:size(b,1)
line([b(i,1) b(i,1)], [b(i,2) b(i,2)+b(i,4)],'color','r');
line([b(i,1)+b(i,3) b(i,1)+b(i,3)],...
[b(i,2) b(i,2)+b(i,4)],'color','r');
line([b(i,1) b(i,1)+b(i,3)], [b(i,2) b(i,2)],'color','r');
line([b(i,1) b(i,1)+b(i,3)],...
[b(i,2)+b(i,4) b(i,2)+b(i,4)],'color','r');
end
title('连通域法');
subplot(212);
imshow(Img);
hold on;
for i = 1:size(horiz_locs,1)
for j = 1:size(perpen_locs{i}, 1)
line([perpen_locs{i}(j,1) perpen_locs{i}(j,1)],...
[horiz_locs(i,1) horiz_locs(i,2)],'color','r');
line([perpen_locs{i}(j,2) perpen_locs{i}(j,2)],...
[horiz_locs(i,1) horiz_locs(i,2)],'color','r');
line([perpen_locs{i}(j,1) perpen_locs{i}(j,2)], ...
[horiz_locs(i,1) horiz_locs(i,1)],'color','r');
line([perpen_locs{i}(j,1) perpen_locs{i}(j,2)], ...
[horiz_locs(i,2) horiz_locs(i,2)],'color','r');
end
end
title('投影法');
end
3 仿真结果
4 参考文献
[1]杨晓娟, and 宋凯. "基于投影法的文档图像分割算法." 成都大学学报:自然科学版 28.2(2009):3.