Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Take a binary image and 'colour' in the black sections. Use floodFill by looping over the whole image and flood filling every black section. 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).

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++;
        }
    }
}

Take a binary image and 'colour' in the black sections. Use sections: use floodFill by looping over the whole image and flood filling every black section. 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).

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++;
        }
    }
}

Take a binary image and 'colour' in the black sections: sections (regions): use floodFill by looping over the whole image and flood filling every black section. 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).

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++;
        }
    }
}

Take a binary image and 'colour' in the black sections (regions): use floodFill by looping over the whole image and flood filling every black section. 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).

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++;
        }
    }
}

Take One way to go about it is to take a binary image 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).

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++;
        }
    }
}

One way to go about it is to take a binary image 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).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++;
        }
    }
}

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++;
        }
    }
}

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 != flt_white)
            section_sizes[colour]++;
    }
}

// No sections (the image was all white)
if(section_sizes.size() == 0)
    continue;

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 != flt_white)
            section_sizes[colour]++;
    }
}

// No sections (the image was all white)
if(section_sizes.size() == 0)
    continue;

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 != flt_white)
> 1)
            section_sizes[colour]++;
    }
}