title: How to calculate number of pixels within selected contour in python
body: <p>I want to calculate selected area. I have a formula but I need to calculate number of pixels in the contour. 
  How can I do ?</p>
  
  <p>Here is my code;</p>
  
  <pre><code>import os
  import cv2
  import logging
  import numpy as np
  from imageio import imread
  import matplotlib
  from matplotlib import pyplot as plt
  import morphsnakes as ms
  
      def _____():
  
      # Load the image.
      img = imread(PATH_IMG_NODULE)[..., 0] / 255.0
  
      # g(I)
      gimg = ms.inverse_gaussian_gradient(img, alpha=1000, sigma=5.48)
  
      # Initialization of the level-set.
      init_ls = ms.circle_level_set(img.shape, (100, 126), 20)
  
      # Callback for visual plotting
      callback = visual_callback_2d(img)
  
      # MorphGAC.
      ms.morphological_geodesic_active_contour(gimg, iterations=45,
                                               init_level_set=init_ls,
                                               smoothing=1, threshold=0.31,
                                               balloon=1, iter_callback=callback)
  </code></pre>
  
  <p>Here is my selected area's picture;</p>
  
  <p><a href="https://i.stack.imgur.com/sW0lc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sW0lc.png" alt="Selected Area"></a></p>
  
  <p>Thank you.</p>