Flood filling for number plate recognition

前端 未结 3 1884
北恋
北恋 2020-12-21 08:54

I have a number plate which is a binary image.

\"enter

I performed dilation to

相关标签:
3条回答
  • 2020-12-21 09:13

    let use this code it will use for you . thanks to @ 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');
    
    0 讨论(0)
  • 2020-12-21 09:20

    You can do this with a few other clever calls to imfill. Here is a way, assuming your binary image is in the array BW:

    Tmp = imfill(BW, 'holes');
    Tmp2 = imfill(Tmp-BW, 'holes');
    Res = Tmp - imfill(BW & Tmp2, 'holes');
    

    and Res is a binary image that contains the desired output:

    enter image description here

    0 讨论(0)
  • 2020-12-21 09:38

    Text is just single layer fill so I do it in C++ like this:

    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
    

    Here are how the stages looks like:

    • stages

    Algorithm is like this:

    1. draw border rectangle for growth fill start with co (some unused color)
    2. grow outer border to nearest text edges with co
    3. fill outer edges (they disappear) with co
    4. create outer fill edge with ci (some unused color)
    5. fill the inside with ci
    6. merge / recolor source and result images

      copy edges from source image and inside from result image the rest is space

    I use my own picture class for images so some members are:


    xs,ys size of image in pixels
    p[y][x].dd is pixel at (x,y) position as 32 bit integer type
    clear(color) - clears entire image
    resize(xs,ys) - resizes image to new resolution

    If you have special characters that have more layers

    then just add more stages ... layer is how many layers of space there can be from most inner space/hole to the outer space also you can loop until no more layer found ...

    0 讨论(0)
提交回复
热议问题