Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def count_color(image: np.ndarray, rgb_color: list):
  2.     """Count a quantity of pixel colors into an image
  3.    
  4.    Parameters
  5.    ----------
  6.    image: np.ndarray
  7.        The numpy array image loaded as rgb channels
  8.    rgb_color: list
  9.        The color as [r, g, b] that you can count
  10.    
  11.    Returns
  12.    -------
  13.        The number of the pixel color into the image
  14.    """
  15.     rows, cols, depth = image.shape
  16.     count = 0
  17.     for row in range(rows):
  18.         for col in range(cols):
  19.             pixel = image[row][col]
  20.             rgb = pixel.tolist()
  21.             if rgb == rgb_color:
  22.                 count += 1
  23.     return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement