0

我有一个包含文本的图像,我想从图像中剪切每个字母。我将如何使用 MATLAB 实现这一目标?

4

2 回答 2

2

最简单的是测试颜色:

找出字母的颜色。

假设这是您的图像,其中包含一个用颜色 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;

现在只保留字母(/字母):

myImage(myImage~=myColor) = NaN

现在您可以使用

surf(myImage)

将其扩展到一个颜色范围(或一组 RGB 颜色,具体取决于您的图像的格式)并不难

于 2013-09-27T08:21:11.333 回答
2

使用图像处理工具箱

如果您有工具箱,您可以快速识别图像中的每个单独字母。

从灰度图像开始,您必须找到一个分割阈值

level = graythresh(Img);

然后将图像转换为二进制

Img = im2bw(Img,level);

Cc = bwconncomp(Img);

您会得到一个结构,其中包含其字段中每个已识别组件的线性索引

Cc.PixelIdxList

See the documentation for those functions to adjust the segmentation to your needs.

Without the Image Processing Toolbox

You have to implement the connected component algorithm yourself.

From the Matlab documentation:

>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.
于 2013-09-27T10:16:07.247 回答