【发布时间】:2018-11-17 01:43:12
【问题描述】:
我正在写一篇关于光学字符识别的论文。我的工作是从图像中正确分割文本字符。
问题是,这种语言的每个文本行都有单词,其中字符通常由直线连接。这些线条的粗细可能相同,也可能不同。
到目前为止,使用投影配置文件,我已经能够分割未连接到任何直线的字符。但是要分割由直线连接的字符,我必须删除这些线。我更喜欢使用霍夫变换来检测和移除这些线条(意思是在 BW 图像中,如果线条中的像素是黑色的,则将其设为白色)。
查看包含文本的示例图像: Sample Image
This 是使用投影轮廓从上图中分割出来的一条线。
而These 是使用霍夫变换检测到的线。
霍夫变换的代码。使用This图片进行测试。
I = imread('line0.jpg');
%I = rgb2gray(I);
BW = edge(I,'canny');
[H,T,R] = hough(BW);
imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
xlabel('\theta'),ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,1,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2));
y = R(P(:,1));
plot(x,y,'s','color','blue');
% Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(I), hold on
grid on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1;lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');
% plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'o','LineWidth',2,'Color','red');
plot(xy(2,1),xy(2,2),'o','LineWidth',2,'Color','blue');
% determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if( len > max_len )
max_len = len;
xy_long = xy;
end
end
关于如何做到这一点的任何想法?任何帮助将不胜感激!
【问题讨论】:
-
只需替换与行值匹配的图像值即可。
标签: matlab image-processing ocr image-segmentation hough-transform