【发布时间】:2013-10-03 10:55:18
【问题描述】:
我有一个包含文本的图像,我想从图像中剪切每个字母。我将如何使用 MATLAB 实现这一目标?
【问题讨论】:
标签: matlab image-processing ocr image-segmentation
我有一个包含文本的图像,我想从图像中剪切每个字母。我将如何使用 MATLAB 实现这一目标?
【问题讨论】:
标签: matlab image-processing ocr image-segmentation
如果您有工具箱,您可以快速识别图像中的每个单独字母。
从灰度图像开始,您必须找到一个分割阈值
level = graythresh(Img);
然后将图像转换为二进制
Img = im2bw(Img,level);
与
Cc = bwconncomp(Img);
您会得到一个结构,其中包含其字段中每个已识别组件的线性索引
Cc.PixelIdxList
请参阅这些函数的文档以根据您的需要调整细分。
你必须自己实现连通分量算法。
来自 Matlab 文档:
>The basic steps in finding the connected components are:
>
>1. Search for the next unlabeled pixel, p.
>2. Use a flood-fill algorithm to label all the pixels in the connected component containing p.
>3. Repeat steps 1 and 2 until all the pixels are labeled.
【讨论】:
最简单的方法是测试颜色:
找出字母的颜色。
假设这是你的图片,包含一个用颜色 5 写的字母 T:
myImage = round(4*rand(6));
myImage(1:2,:) = 5; %Drawing the top bar of the T
myImage(:,3:4) = 5; %Drawing the leg of the t
myColor = 5;
现在只保留字母(/letters):
myImage(myImage~=myColor) = NaN
现在您可以使用
绘制它surf(myImage)
将其扩展到一个颜色范围(或一组 RGB 颜色,具体取决于您的图像的格式)并不难
【讨论】: