Advertisement
Guest User

Island Labeler

a guest
Oct 25th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | Source Code | 0 0
  1.         no_alpha = cv2.cvtColor(island_data, cv2.COLOR_RGBA2RGB)
  2.         img = no_alpha.copy()
  3.         #cv2.imshow("Image", no_alpha)
  4.         #cv2.waitKey()
  5.         for color in range(1, 255):
  6.             seeds = np.argwhere(img[:, :, 2] > 250)
  7.             if seeds.size > 0:
  8.                 seed_coord = seeds[0]
  9.             else:
  10.                 print("gaben")
  11.                 break
  12.  
  13.             #try:
  14.             #    seed_coord = next(i for i, val in np.ndenumerate(img[:, :, 2]) if val > 250)
  15.             #except:
  16.             #    break
  17.             print(f"Seed Coord: {seed_coord}")
  18.             floodval = (0, color, 0)
  19.             lower_range = np.array([0, color, 0])
  20.             upper_range = np.array([0, color, 0])
  21.             print(img[seed_coord[0], seed_coord[1]])
  22.             cv2.floodFill(img, None, seedPoint=seed_coord, newVal=floodval)
  23.             print(img[seed_coord[0], seed_coord[1]])
  24.             mask = cv2.inRange(img, lower_range, upper_range)
  25.             print(seed_coord)
  26.             cv2.imshow("image", img)
  27.             cv2.waitKey()
  28.             cv2.imshow("image", mask)
  29.             cv2.waitKey()
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement