Blob detection for opencv image feature detection

As mentioned earlier, the detection of image feature points includes corner points and blobs. Today, blobs refer to areas in a two-dimensional image that have color differences and grayscale differences between and surrounding colors. Because blobs represent an area, their Compared with simple corner points, it has better stability and better anti-interference ability.

  The main idea of ​​speckle detection in the visual field is to detect the area in the image that is larger than the gray value of the surrounding pixels or smaller than the gray value of the surrounding area. Generally speaking, there are two basic methods.

  1. Differential method based on derivation, which becomes the differential detector

  2. The watershed algorithm based on local extreme value, the simpleBlobDetector feature detector is provided in OPENCV to realize this basic blob detection algorithm.

  

  LOG speckle detection

  Using the Gaussian Laplace operator to detect image blobs is a relatively common method. For a two-dimensional Gaussian function G(x, y, o), after the normalized Laplace transform, the result is in two dimensions. The image is presented as a circularly symmetric function, we can use this function to detect the blobs of the image, and by changing the value of o

to detect two-dimensional blobs of different sizes. The image is as follows

  

  The intuitive understanding of the above passage is: the convolution operation of an image and a two-dimensional function is actually to find the similarity between the image and this function. Similarly, the image is convolved with the Gaussian Laplacian function, It is to find the similarity between the image and the Gaussian Laplace function, when the size of the spots in the image is the same as the shape of the Gaussian Laplace function.

When the state of the image tends to be consistent, the Laplace response of the corresponding position of the image reaches the maximum.

  In fact, the lapacian operator itself can detect the extreme point of the image, and it is set as the L operator, but because the L operator cannot eliminate the interference, the noise in the image M will affect the obtained result, so the image M is performed on The Gaussian filter named G removes the interference and obtains the image M'. The formula is as follows: M' = M*G*L=M*(G*L); the parentheses are

Gaussian Laplacian.

  Through the above algorithm, we can get blobs, but there are no multi-scale blobs. When the Gaussian covariance o is certain, we can only detect blobs corresponding to the radius of o. When o=r/root sign 2, the response is the largest, and when the black and white of the image is inverted, the response is the smallest, because

This makes the o-value at which the Gaussian Laplacian response reaches the peak value and becomes the characteristic scale.

  Corresponding to the two-dimensional image, calculate the discrete Gaussian Laplace response value of the image at different scales, and then check each value in the different scale positions, if the Gaussian Laplace response value at a certain scale is less than or greater than other scale values, then the point is the detected image blob location.

 

  2. Watershed Algorithm Based on Local Extremum Blob Detection SimpleBlobDetector

  This detection method is divided into the following steps

  a. For a picture, set a low threshold, set a high threshold, set a threshold step, and then take a series of thresholds from the low threshold to the high threshold according to the threshold step

  b. Binarize the image with each threshold, then use findcontours to find edges and calculate the center of each contour

  c. Corresponding to the center of the contour of each image, suppress it, and define a minimum distance. The feature center in this distance area is defined as a blob, and a set of feature points is obtained.

  d. Perform corresponding filtering on feature points, such as color filtering, area filtering, etc.

  API:Ptr<smpleBlobDetector>create(simpleBlobDetector::params parameter collection)

  The parameter set includes minthreshold low threshold maxthreshold high threshold threshold step threshold step minDistanceBetweenBlob blob block minimum distance filterColor color filter filterArea area filter

          There are two filterByCircularrty roundness filtering, border length filtering and convexity filtering. These five filtering methods are optional and only one of them can be selected. By default, black color filtering is used.

  The specific code is as follows

int main(int argc,char* argv[])
{
    Mat srcImage = imread("F:\\opencv\\OpenCVImage\\FeatureDetectSrc1.jpg");
    Mat srcGrayImage;
    if (srcImage.channels() == 3)
    {
        cvtColor(srcImage,srcGrayImage,CV_RGB2GRAY);
    }
    else
    {
        srcImage.copyTo(srcGrayImage);
    }
    vector<KeyPoint>detectKeyPoint;
    Mat keyPointImage1,keyPointImage2;

    SimpleBlobDetector::Params params;
    params.minArea = 10;
    params.maxArea = 1000;
    params.filterByCircularity = true;
    Ptr<SimpleBlobDetector> sbd = SimpleBlobDetector::create(params);
    sbd->detect(srcGrayImage,detectKeyPoint);
    drawKeypoints(srcImage,detectKeyPoint,keyPointImage1,Scalar(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    drawKeypoints(srcImage,detectKeyPoint,keyPointImage2,Scalar(0,0,255),DrawMatchesFlags::DEFAULT);

    imshow("src image",srcImage);
    imshow("keyPoint image1",keyPointImage1);
    imshow("keyPoint image2",keyPointImage2);

    imwrite("F:\\opencv\\OpenCVImage\\FeatureDetectSrc1SimpleBlobDetectorKeyPointImageDefault.jpg",keyPointImage2);

    waitKey(0);
    return 0;
}

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324437770&siteId=291194637