【问题标题】:How do you segment an image containing text?如何分割包含文本的图像?
【发布时间】:2013-10-03 10:55:18
【问题描述】:

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

【问题讨论】:

    标签: matlab image-processing ocr image-segmentation


    【解决方案1】:

    使用图像处理工具箱

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

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

    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.
    

    【讨论】:

      【解决方案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;
      

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

      myImage(myImage~=myColor) = NaN
      

      现在您可以使用

      绘制它
      surf(myImage)
      

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

      【讨论】:

      • @طالبةعلم 我已经扩展了我的示例以使其更有意义,现在它实际上包含一个字母。
      • 非常感谢您
      猜你喜欢
      • 2011-02-06
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2022-10-17
      • 1970-01-01
      • 2017-03-28
      相关资源
      最近更新 更多