洪水填充用于车牌识别

3

我有一个车牌,它是一张二进制图像。

enter image description here

我对图像进行了膨胀操作以加粗边缘,然后进行了"泛洪填充",最后进行了侵蚀操作以使其变细。

enter image description here

但是我希望我的输出是这样的:

enter image description here

请问有人可以帮助我吗?并且告诉我如何获得所需的输出结果。
ab=imread('test1.png');

level=graythresh(ab);
ab=im2bw(ab,level);

se=strel('disk',1);
ab=imdilate(ab,se); 


ab=imfill(ab,'holes');
ab=bwmorph(ab,'thin',1);
ab=imerode(ab,strel('line',3,90));

figure();imshow(ab,[]); title('floodFilling');

发布(相关部分的)代码可能有助于您获得良好的答案。 - Luis Mendo
3个回答

6
您可以通过调用imfill几个巧妙的方法来实现这一点。下面是一种方式,假设您的二进制图像在数组BW中:
Tmp = imfill(BW, 'holes');
Tmp2 = imfill(Tmp-BW, 'holes');
Res = Tmp - imfill(BW & Tmp2, 'holes');

并且Res是一个包含所需输出的二进制图像:

enter image description here


0

文本只是单层填充,所以我用C++这样做:

int x,y,e;
int c0=0x00000000; // space color
int c1=0x00FFFFFF; // edge color
int co=0x00FF0000; // outside tmp color
int ci=0x000000FF; // inside tmp color
// grow/flood fill c0 neigbouring c1 with c2
#define fill(c0,c1,c2)\
for (e=1;e;)\
 for (e=0,y=1;y<pic1.ys-1;y++)\
  for (   x=1;x<pic1.xs-1;x++)\
   if (pic1.p[y][x].dd==c0)\
    if ((pic1.p[y-1][x].dd==c1)\
      ||(pic1.p[y+1][x].dd==c1)\
      ||(pic1.p[y][x-1].dd==c1)\
      ||(pic1.p[y][x+1].dd==c1)) { e=1; pic1.p[y][x].dd=c2; }
// copy data pic0 is source pic1 is output
pic1=pic0;
// 0. draw border rectangle for growth fill start with co
for (x=0        ,y=0;y<pic1.ys;y++) pic1.p[y][x].dd=co;
for (x=pic1.xs-1,y=0;y<pic1.ys;y++) pic1.p[y][x].dd=co;
for (x=0,y=0        ;x<pic1.xs;x++) pic1.p[y][x].dd=co;
for (x=0,y=pic1.ys-1;x<pic1.xs;x++) pic1.p[y][x].dd=co;
fill(c0,co,co); // 1. grow outer border
fill(c1,co,co); // 2. grow outer edges
fill(c0,co,ci); // 3. create outer fill edge
fill(c0,ci,ci); // 4. fill the inside
// 5. merge / recolor
for (y=0;y<pic1.ys;y++)
 for (x=0;x<pic1.xs;x++)
    {
    e=c0;
    if ((pic0.p[y][x].dd==c1)||(pic1.p[y][x].dd==ci)) e=c1;
    pic1.p[y][x].dd=e;
    }
#undef fill

这是阶段的样子:

  • stages

算法如下:

  1. 绘制带有co(某些未使用的颜色)的生长填充起始点的边框矩形
  2. 将外边框扩展到最近的文本边缘,使用co
  3. 使用co填充外部边缘(它们会消失)
  4. 创建带有ci(某些未使用的颜色)的外部填充边缘
  5. 使用ci填充内部
  6. 合并/重新着色源图像和结果图像

    从源图像复制边缘,从结果图像复制内部,其余是空白区域

我使用自己的图片类来处理图片,因此一些成员变量是:


xs,ys:图片的像素大小
p[y][x].dd:32位整数类型的(x,y)位置处的像素
clear(color):清除整个图像
resize(xs,ys):调整图像的分辨率

如果您有具有更多层的特殊字符

然后只需添加更多的阶段... 是从最内部空间/孔到外部空间可以有多少层,也可以循环直到找不到更多的层。


-1

使用这段代码,它将为您提供帮助。感谢 @spektre。

 ab=imread('test1.png');

level=graythresh(ab);
ab=im2bw(ab,level);

se=strel('disk',1);
ab=imdilate(ab,se);
figure();imshow(ab,[]); title('floodFilling');
ab1=imfill(ab,'holes');
ab1(ab==1)=0;
figure();imshow(ab1,[]); title('floodFilling');

1
这并没有回答问题,输出结果与提问者所要求的完全不同。 - Ratbert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接