title: How to deduce automatically if the processed image needs morphological post-processing or not?
body: <ul>
  <li>I have done segmentation using Deep-Learning, after that, I have noticed that sometimes the segmented shapes seems to be good, and sometimes, it needs more post-processing with <strong>morphological operations</strong>.</li>
  <li>The segmented shape is a ring, and in rare cases is filled circle, as you can see in the attached images.</li>
  <li>When this ring segmentation is closed shape, there are no issues, but <strong>when the ring is open there is a problem, because I can't measure the internal area (inside the ring) correctly</strong> and the area calculation is the objective of the whole project.</li>
  <li>So how can I detect automatically if my segmented image needs post-processing (using morphological operations) and what kind of morphology is preferred in this case? so I can calculate the area as mentioned <a href="https://stackoverflow.com/questions/61681565/how-to-calculate-the-internal-areacount-of-pixels-inside-a-ring-like-shape">here</a>.</li>
  </ul>
  
  <p><strong>Thanks in Advance</strong></p>
  
  <p><a href="https://i.stack.imgur.com/TNmWH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TNmWH.png" alt="image1"></a>
  <a href="https://i.stack.imgur.com/GAzfn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GAzfn.png" alt="image2"></a>
  <a href="https://i.stack.imgur.com/7aGR1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7aGR1.png" alt="image3"></a>
  <a href="https://i.stack.imgur.com/vRONt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vRONt.png" alt="image4"></a></p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from skimage.io import imread, imsave
  # import scipy.ndimage as ndi 
  from skimage import morphology, filters, feature
  
  seg = imread('prediction.png')
  # meijering alpha=None,
  # rem2 = morphology.remove_small_objects(seg, 4)
  resf = filters.meijering(seg, sigmas=range(1, 3, 1),  black_ridges=False)
  
  sobel = filters.sobel(resf)
  # diam = morphology.diameter_closing(sobel, 64, connectivity=2)
  gaussian = filters.gaussian(sobel, sigma= 1)
  val = filters.threshold_otsu(gaussian)
  resth = gaussian &lt; val 
  
  # Morphology
  SE = morphology.diamond(2)
  # SE = np.ones((3,3))
  # SE = morphology.disk(2)
  # SE = square(7)
  # SE = rectangle(3,3)
  # SE = octagon(3, 3)
  
  erosion  = morphology.binary_erosion( resth, SE).astype(np.uint8)
  dilation = morphology.binary_dilation(resth, SE).astype(np.uint8)
  opening  = morphology.binary_opening( resth, SE).astype(np.uint8)
  closing  = morphology.binary_closing( resth, SE).astype(np.uint8)
  #thinner = morphology.thin(erosion, max_iter=4)
  
  rem  = morphology.remove_small_holes(resth, 2)
  
  # entropy  = filters.rank.entropy(resth, SE) 
  # print(seg.shape)
  
  plt.figure(num='PProc')
  # 1
  plt.subplot('335')
  plt.imshow(rem,cmap='gray')
  plt.title('rem')
  plt.axis('off')
  # 2
  plt.subplot('336')
  plt.imshow(dilation,cmap='gray')
  plt.title('dilation')
  plt.axis('off')
  # 3
  plt.subplot('337')
  plt.imshow(opening,cmap='gray')
  plt.title('opening')
  plt.axis('off')
  # 4
  plt.subplot('338')
  plt.imshow(closing,cmap='gray')
  plt.title('closing')
  plt.axis('off')
  # 5
  plt.subplot('332')
  plt.imshow(seg,cmap='gray')
  plt.title('segmented')
  plt.axis('off')
  # 6
  plt.subplot('333')
  plt.imshow(resf,cmap='gray')
  plt.title('meijering')
  plt.axis('off')
  # 7
  # 8
  plt.subplot('334')
  plt.imshow(resth,cmap='gray')
  plt.title('threshold_otsu')
  plt.axis('off')
  # 9
  plt.subplot('339')
  plt.imshow(erosion,cmap='gray')
  plt.title('erosion')
  plt.axis('off')
  #
  plt.show()
  
  </code></pre>