Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One solution would be to apply dilation and erosion and find all contours that are smaller than X-pixels and fill them with white color:</p> <pre><code>int main() { // Load the image as a Grayscale Mat image = imread("image.jpg", CV_LOAD_IMAGE_GRAYSCALE); // Threshold the image image = image &gt; 120; // Create bigger image with image width and height + 10 pixels Mat image_big = Mat::zeros( image.size().height + 10, image.size().width + 10, CV_8UC1 ); // Set bigger image to be all white image_big.setTo(255); Mat image_big_copy; // This may vary, you must find it for yourself // Dilate image 4 times and erode once dilate(image, image, Mat(), Point(-1,-1), 4); erode(image, image, Mat(), Point(-1,-1)); // Copy image in the center of bigger image so you left 5px around image blank/white // Create a new ROI that points to center of the bigger image Mat image_big_roi = image_big( Rect(Point(5, 5), Size(image.size())) ); // Copy image to the bigger image ROI addWeighted(image_big_roi, 0., image, 1., 0., image_big_roi); // Create a data copy of image_big image_big.copyTo(image_big_copy); // Find all contours in a given image and store them in contours vector&lt;vector&lt;Point&gt; &gt; contours; findContours(image_big_copy, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); for( int i = 0; i &lt; contours.size(); i++ ) { // This is your condition to filter out unwanted contours etc. // For every contour if its area is bigger/smaller than the sum of pixels if ( fabs(contourArea(Mat(contours[i]))) &lt; 800 ) { // Fill a contour with white color drawContours(image_big, contours, i, Scalar(255), CV_FILLED); } } imshow("Image original", image); imshow("Image edited", image_big); waitKey(0); return 0; } </code></pre> <p>Original image:</p> <p><img src="https://i.stack.imgur.com/fCsWs.jpg" alt="enter image description here"></p> <p>After:</p> <p><img src="https://i.stack.imgur.com/SOopS.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload