title: removing pixels less than n size(noise) in an image - open CV python
body: <p>i am trying to remove noise in an image less and am currently running this code</p>
  
  <pre><code>import numpy as np
  import argparse
  import cv2
  from skimage import morphology
  
  # Construct the argument parser and parse the arguments
  ap = argparse.ArgumentParser()
  ap.add_argument("-i", "--image", required = True,
      help = "Path to the image")
  args = vars(ap.parse_args())
  
  # Load the image, convert it to grayscale, and blur it slightly
  image = cv2.imread(args["image"])
  
  cv2.imshow("Image", image)
  cv2.imwrite("image.jpg", image)
  
  greenLower = np.array([50, 100, 0], dtype = "uint8")
  greenUpper = np.array([120, 255, 120], dtype = "uint8")
  
  green = cv2.inRange(image, greenLower, greenUpper)
  #green = cv2.GaussianBlur(green, (3, 3), 0)
  
  cv2.imshow("green", green)
  cv2.imwrite("green.jpg", green)
  
  cleaned = morphology.remove_small_objects(green, min_size=64, connectivity=2)
  
  cv2.imshow("cleaned", cleaned)
  cv2.imwrite("cleaned.jpg", cleaned)
  
  
  
  cv2.waitKey(0)
  </code></pre>
  
  <p>However, the image does not seem to have changed from "green" to "cleaned" despite using the remove_small_objects function. why is this and how do i clean the image up? Ideally i would like to isolate only the image of the cabbage. </p>
  
  <p>My thought process is after thresholding to remove pixels less than 100 in size, then smoothen the image with blur and fill up the black holes surrounded by white - that is what i did in matlab. If anybody could direct me to get the same results as my matlab implementation, that would be greatly appreciated. Thanks for your help.</p>
  
  <p>Edit: made a few mistakes when changing the code, updated to what it currently is now and display the 3 images</p>
  
  <p>image:</p>
  
  <p><a href="https://i.stack.imgur.com/RcVLq.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/RcVLq.jpg" alt="enter image description here"></a></p>
  
  <p>green:</p>
  
  <p><a href="https://i.stack.imgur.com/i36uk.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/i36uk.jpg" alt="enter image description here"></a></p>
  
  <p>clean:</p>
  
  <p><a href="https://i.stack.imgur.com/pz5SI.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/pz5SI.jpg" alt="enter image description here"></a></p>
  
  <p>my goal is to get somthing like this picture below from matlab implementation:</p>
  
  <p><a href="https://i.stack.imgur.com/6roQh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6roQh.png" alt="enter image description here"></a></p>