2013-06-07 12 views
7

Mam obraz binarny, który zawiera kilka obiektów typu blob.Usuwanie obiektów typu blob z obrazu binarnego

Chcę usunąć obiekty typu blob, które są mniejsze niż pewien obszar.

Czy ktoś może mi zaproponować sposób?

Używam Open-CV. zrobiłem dylatację i erozję, aby uzyskać te plamki. więc potrzebuję czegoś innego, aby usunąć rozlanie plam, które są mniejsze niż pewien obszar.

+1

1. algorytm etykietowania run conncomp. 2. Wyrzuć obszary o wielkości mniejszej niż próg. Innym wariantem jest N-krotna erozja i po N-krotnym rozszerzeniu (ale im wyższa N gorsza restavracja plam) –

+0

Czy możesz podać przykładowy obraz? – by0

Odpowiedz

1

można zrobić coś takiego:

// 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<vector<Point>> contours; 
vector<Vec4i> hierarchy; 
vector<int> 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<contours.size(); ++i) { 
     contour_area = contourArea(contours_all[i]) ; 
     if (contour_area < threshold) 
      small_blobs.push_back(i); 
    } 
} 

// fill-in all small contours with zeros 
for (size_t i=0; i < small_blobs.size(); ++i) { 
    drawContours(binary_image, contours, small_blobs[i], cv::Scalar(0), 
               CV_FILLED, 8); 
} 
+1

Czy ktoś może mi wyjaśnić, w jaki sposób doszło do contours_all w przypadku, jeśli? i co zawiera. Nie mogłem zrozumieć –

0
  //src_gray is your image that we threshold 
      threshold(src_gray, threshold_output, NULL, 255, THRESH_OTSU); 
      /// Find contours 
      findContours(threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0)); 
      /// Approximate contours 
      vector<Rect> boundRect(contours.size()); 
      for (unsigned int i = 0; i < contours.size(); i++) 
      { //identify bounding box 
       boundRect[i] = boundingRect(contours[i]); 
      } 
      for (unsigned int i = 0; i < contours.size(); i++) 
      { 

       if ((boundRect[i].area() < //enter your area here)) 
       { 
        src_gray(boundRect[i])=//set it to whatever value you want; 
       } 
      } 

Więc spróbuj tego ...

Powiązane problemy