Ask Your Question
0

Blob coloring not blob detection

asked 2018-05-03 05:29:19 -0600

cjacquel gravatar image

Hello,

I am searching for the blob coloring source code in Opencv. Blob coloring is different from blob detection.

Blob coloring give an unique number to each region of the image.

Thank you, cjacquel

edit retag flag offensive close merge delete

Comments

1

connrctedComponents() might be an idea

berak gravatar imageberak ( 2018-05-04 01:25:42 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-03 11:54:35 -0600

sjhalayka gravatar image

updated 2018-05-03 12:51:24 -0600

One way to go about it is to take a binary image (pixels with value 0.0 or 1.0) and 'colour' in the black sections (regions): use floodFill by looping over the whole image and flood filling every black pixel. In the end, you are left with a white outline with a value of 1, and each distinct section filled with a value larger than 1 (a unique ID). It doesn't have to use floats, I just like floats. :)

int section_count = 0;
int fill_colour = 2;

for(int j = 0; j < flt_canny.rows; j++)
{
    for(int i = 0; i < flt_canny.cols; i++)
    {
        float colour = flt_canny.at<float>(j, i);

        if(colour == 0)
        {
            floodFill(flt_canny, Point(i, j), Scalar(fill_colour));

            section_count++;
            fill_colour++;
        }
    }
}

// Get number of pixels per section colour
map<float, int> section_sizes;

for(int j = 0; j < flt_canny.rows; j++)
{
    for(int i = 0; i < flt_canny.cols; i++)
    {
        float colour = flt_canny.at<float>(j, i);

        if(colour > 1)
            section_sizes[colour]++;
    }
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-03 05:29:19 -0600

Seen: 240 times

Last updated: May 03 '18