I have a binary image which contain few blobs.
I want to remove blobs which are less than a certain area.
Can any one suggest me a way?
I am using Open-C
You can do something like this:
// your input binary image
// assuming that blob pixels have positive values, zero otherwise
Mat binary_image;
// threashold specifying minimum area of a blob
double threshold = 100;
vector> contours;
vector hierarchy;
vector small_blobs;
double contour_area;
Mat temp_image;
// find all contours in the binary image
binary_image.copyTo(temp_image);
findContours(temp_image, contours, hierarchy, CV_RETR_CCOMP,
CV_CHAIN_APPROX_SIMPLE);
// Find indices of contours whose area is less than `threshold`
if ( !contours_all.empty()) {
for (size_t i=0; i