Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. def check_colors(image, reference_colors = [[128, 0, 0], [0, 0, 128], [0, 0, 0]]):
  2.  
  3. colors_on_image = set( tuple(v) for m2d in image for v in m2d )
  4. if len(colors_on_image) != 2:
  5. return False
  6.  
  7. for color in colors_on_image:
  8. if not np.any(reference_colors == color):
  9. return False
  10.  
  11. return True
  12.  
  13. def check_object_sizes(image, objects_colors = [[128, 0, 0], [0, 0, 128]], tresh = 0.1):
  14.  
  15. mask = np.full(image.shape, False, dtype = bool)
  16. for color in objects_colors:
  17. mask = np.logical_or(mask, image == color)
  18.  
  19. return ((mask.sum() / np.prod(image.shape)) >= tresh)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement