go_away

Author Topic: Problem with blob labeling  (Read 1395 times)

0 Members and 1 Guest are viewing this topic.

Offline CommanderbobTopic starter

  • Robot Overlord
  • ****
  • Posts: 146
  • Helpful? 2
  • Embeddedmicro.com
Problem with blob labeling
« on: February 01, 2009, 08:46:36 PM »
I need to take an image, that I removed everything except two colors, a red and a green, and label the blobs of color as discussed in the computer vision tutorial. The problem is that it sometimes splits a blob into two separate blobs due to the way I scan the pixels, left to right, top to bottom. I attached an image of the output. Each different shade is a different group.

Here is my code
Code: [Select]
    for (i=0;i<(cinfo.output_height*row_stride);i+=3) //for each pixel
    {
        cur_row=i/row_stride;//row we are on
        cur_pix=(i-(cur_row*row_stride));//pixel we are on * 3 because of RGB
        if (imgdec[i+2]==1)//if marked as red object
        {
            if (cur_pix&&imgdec[i-1]==1&&imgdec[i-3])//top
            {
                imgdec[i]=imgdec[i-3];
            }
            else if (cur_row&&cur_pix&&imgdec[i-1-row_stride]==1&&imgdec[i-3-row_stride])//top left
            {
                imgdec[i]=imgdec[i-3-row_stride];
            }
            else if (cur_row&&imgdec[i+2-row_stride]==1&&imgdec[i-row_stride])//top center
            {
                imgdec[i]=imgdec[i-row_stride];
            }
            else if (cur_row&&cur_pix!=(row_stride-3)&&imgdec[i+5-row_stride]==1&&imgdec[i+3-row_stride])//top right
            {
                imgdec[i]=imgdec[i+3-row_stride];
            }
            else //new object
            {
                obj_r++;
                imgdec[i]=obj_r;
            }
        }
        else if (imgdec[i+2]==2)//if marked as green object
        {
            if (cur_pix&&imgdec[i-1]==2&&imgdec[i-2])
            {
                imgdec[i+1]=imgdec[i-2];
            }
            else if (cur_row&&cur_pix&&imgdec[i-1-row_stride]==2&&imgdec[i-2-row_stride])
            {
                imgdec[i+1]=imgdec[i-2-row_stride];
            }
            else if (cur_row&&imgdec[i+2-row_stride]==2&&imgdec[i+1-row_stride])
            {
                imgdec[i+1]=imgdec[i+1-row_stride];
            }
            else if (cur_row&&cur_pix!=(row_stride-3)&&imgdec[i+5-row_stride]==2&&imgdec[i+4-row_stride])
            {
                imgdec[i+1]=imgdec[i+4-row_stride];
            }
            else
            {
                obj_g++;
                imgdec[i+1]=obj_g;
            }
        }
    }

The problem is that it only checks the top and left pixels as the ones under it and to the right have not been grouped yet. What happens is if there is a corner that sticks out two pixels then it is assigned to a new group and everything after that is in that group.

I can't think of any way to make this work and still be fast. This is running on a Gumstix with 320*240 images. I need to get the best FPS as possible.

Also the attached images colors were enhanced so you could see the color of each group better as group 1 would be almost black otherwise (1/255).

Thanks for any help,
Justin

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Problem with blob labeling
« Reply #1 on: February 13, 2009, 12:53:15 AM »
I don't quite understand the question . . . are you trying to detect only a single object, or multiple objects?

Quote
What happens is if there is a corner that sticks out two pixels then it is assigned to a new group and everything after that is in that group.
Add in a 'ignore noise' function. Basically its an IF statement that checks to see if a pixel is connected to other pixels of a blob. Ignore that pixel if 'no'.

You can also do a pixel count within a blob. Ignore/delete all blobs of a certain minimum number of pixels.

Hope that helps?

Offline CommanderbobTopic starter

  • Robot Overlord
  • ****
  • Posts: 146
  • Helpful? 2
  • Embeddedmicro.com
Re: Problem with blob labeling
« Reply #2 on: February 13, 2009, 09:28:11 AM »
I am trying to detect a single object of two colors and it is very important to know which of the two colors is on top.

The problem was not the small objects but if the edge of an object was rough, i.e. parts stuck out of it. As you can see in the picture each shade represents a different group. The large main object is split into many groups due to this problem. Look at the left of were the new group started.

I fixed this problem by having it store all the groups that touch and later rename them into the same group.

Justin

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Problem with blob labeling
« Reply #3 on: February 13, 2009, 08:48:29 PM »
Quote
I am trying to detect a single object of two colors and it is very important to know which of the two colors is on top.
Do two blob detection runs - one for each color. Then just compare the Y centroid value for which blob is on top.

Quote
The problem was not the small objects but if the edge of an object was rough, i.e. parts stuck out of it. As you can see in the picture each shade represents a different group. The large main object is split into many groups due to this problem. Look at the left of were the new group started.

I fixed this problem by having it store all the groups that touch and later rename them into the same group.
You can also fix this problem by doing a smoothing or blurring function, basically telling each pixel to slightly shift its color to match the color of nearby pixels based on some threshold. This gets rid of edge roughness.

 


Get Your Ad Here