Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to remove the small blobs?

I want to erase the small white spots areas to keep the largest area (white colour) in the picture:

Before

Before

I used findContours and found the largest area then used drawContours. I got the following result:

After

My code

findContours(image, vtContours, vtHierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

for (int i = 0; i < vtContours.size(); i++)
{
    double area = contourArea(vtContours[i]);

    if (area <= 100) {
        continue;
    }

    // Get only one
    if (area > dMaxArea)
    {
        dMaxArea = area;
        nSavedContour = i;
    }

}

if (nSavedContour == -1)
{
    return false;
}

image = Scalar::all(0);
drawContours(image, vtContours, nSavedContour, Scalar(255), CV_FILLED, 8);

Can you show me the other idea or my fault? Thank for supporting!

How to remove the small blobs?

I want to erase the small white spots areas to keep the largest area (white colour) in the picture:

Before

Before

I used findContours and found the largest area then used drawContours. I got the following result:

After

My code

findContours(image, vtContours, vtHierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

for (int i = 0; i < vtContours.size(); i++)
{
    double area = contourArea(vtContours[i]);

    if (area <= 100) {
        continue;
    }

    // Get only one
    if (area > dMaxArea)
    {
        dMaxArea = area;
        nSavedContour = i;
    }

}

if (nSavedContour == -1)
{
    return false;
}

image = Scalar::all(0);
drawContours(image, vtContours, nSavedContour, Scalar(255), CV_FILLED, 8);

Can you show me the other idea or my fault? Thank for supporting!

How to remove the small blobs?

I want to erase the small white spots areas to keep the largest area (white colour) in the picture:

Before

Before

I used findContours and found the largest area then used drawContours. I got the following result:

After

My code

findContours(image, vtContours, vtHierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

for (int i = 0; i < vtContours.size(); i++)
{
    double area = contourArea(vtContours[i]);

    if (area <= 100) {
        continue;
    }

    // Get only one
    if (area > dMaxArea)
    {
        dMaxArea = area;
        nSavedContour = i;
    }

}

if (nSavedContour == -1)
{
    return false;
}

image = Scalar::all(0);
drawContours(image, vtContours, nSavedContour, Scalar(255), CV_FILLED, 8);

Can you show me the other idea or my fault? Thank for supporting!

How to remove the small blobs?

I want to erase the small white spots areas to keep the largest area (white colour) in the picture:

Before

Before

I used findContours and found the largest area then used drawContours. I got the following result:

After

My code

findContours(image, vtContours, vtHierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

for (int i = 0; i < vtContours.size(); i++)
{
    double area = contourArea(vtContours[i]);

    if (area <= 100) {
        continue;
    }

    // Get only one
    if (area > dMaxArea)
    {
        dMaxArea = area;
        nSavedContour = i;
    }

}

if (nSavedContour == -1)
{
    return false;
}

image = Scalar::all(0);
drawContours(image, vtContours, nSavedContour, Scalar(255), CV_FILLED, 8);

Can you show me the other idea or my fault? Thank for supporting!