Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blob extraction in OpenCV

I'm using OpenCV to filter an image for certain colours, so I've got a binary image of the detected regions.

Now I want to erode those areas and then get rid of the smaller ones, and find the x,y coordinates of the largest 'blob'

I was looking for recommendations as to what the best library would be to use? I've seen cvBlob and cvBlobsLib but I'm not too sure how to set them up. Do I want to compile them along with the project or do I want to compile and install them to the system (like I did with OpenCV)?

I'm currently using the Code::Blocks IDE on Ubuntu (although that shouldn't restrict things)

like image 623
amr Avatar asked Jan 09 '11 21:01

amr


People also ask

What is blob detection in OpenCV?

Blob stands for Binary Large Object and refers to the connected pixel in the binary image. The term "Large" focuses on the object of a specific size, and that other "small" binary objects are usually noise.

What is blob in image processing?

The method of analyzing an image that has undergone binarization processing is called "blob analysis". A blob refers to a lump. Blob analysis is image processing's most basic method for analyzing the shape features of an object, such as the presence, number, area, position, length, and direction of lumps.

What is blob detection used for?

In computer vision, blob detection methods are aimed at detecting regions in a digital image that differ in properties, such as brightness or color, compared to surrounding regions.

How do you detect an ellipse in OpenCV?

To identify circles, ellipses, or in general, any shape in which the pixels are connected we use the SimpleBlobDetector() function of OpenCV.


2 Answers

I'm late to the party, but I'd just like to chime in that there is a way to do connected components in opencv, it's just not mainlined yet.

Update: It is mainlined, it's just been stuck waiting for 3.0 to release for multiple years. Linky to documentation

See http://code.opencv.org/issues/1236 and http://code.opencv.org/attachments/467/opencv-connectedcomponents.patch

Disclaimer - I'm the author.

like image 189
Jason Newton Avatar answered Sep 21 '22 13:09

Jason Newton


You can use findContours to do that, see the opencv manual and a Tutorial to find connected components.


Edit: Code from the tutorial (via Archive.org)

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
{
    IplImage *img, *cc_color; /*IplImage is an image in OpenCV*/
    CvMemStorage *mem;
    CvSeq *contours, *ptr;
    img = cvLoadImage(argv[1], 0); /* loads the image from the command line */
    cc_color = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);

    cvThreshold(img, img, 150, 255, CV_THRESH_BINARY);
    mem = cvCreateMemStorage(0);
    cvFindContours(img, mem, &contours, sizeof(CvContour), CV_RETR_CCOMP,
        CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));


    for (ptr = contours; ptr != NULL; ptr = ptr->h_next) {
        CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
        cvDrawContours(cc_color, ptr, color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
    }

    cvSaveImage("result.png", cc_color);
    cvReleaseImage(&img);
    cvReleaseImage(&cc_color);
    return 0;
}
like image 22
etarion Avatar answered Sep 24 '22 13:09

etarion