Sagar Bharadwaj commited on
Commit
5461b2c
·
1 Parent(s): 7708b6c

Small changes in gen island

Browse files
Files changed (1) hide show
  1. colorbynumber/gen_islands.py +4 -9
colorbynumber/gen_islands.py CHANGED
@@ -2,12 +2,8 @@ import cv2 as cv
2
  import numpy as np
3
 
4
  class GenerateIslands:
5
- def __init__(self,
6
- indices_color_choices,
7
- gradient_kernel_size = 4,
8
- ):
9
  self.indices_color_choices = indices_color_choices
10
- self.gradient_kernel = np.ones((gradient_kernel_size, gradient_kernel_size), np.uint8)
11
 
12
  # List of coordinates for each islands border
13
  self.island_borders = {}
@@ -72,7 +68,7 @@ class GenerateIslands:
72
  for cntr_id, contour in enumerate(contours):
73
  area_fraction_perc = (cv.contourArea(contour) / total_area) * 100
74
  if area_fraction_perc >= area_perc_threshold:
75
- cv.drawContours(contours_image, contours, cntr_id, (0,255,0), 4)
76
 
77
  # If the shape is not valid, return a blank image
78
  return contours_image
@@ -107,7 +103,6 @@ class GenerateIslands:
107
  def get_islands(self, border_padding=2, area_perc_threshold=0.05,
108
  arc_length_area_ratio_threshold=0.1):
109
  for color_index in np.unique(self.indices_color_choices):
110
- print(color_index)
111
  self._get_islands_for_one_color(
112
  color_index = color_index,
113
  border_padding = border_padding,
@@ -118,7 +113,7 @@ class GenerateIslands:
118
  # Flatten the list of borders
119
  island_borders_list = []
120
  for color_id in self.island_borders:
121
- if len(self.island_borders[color_id][1]) > 0:
122
- island_borders_list += self.island_borders[color_id]
123
 
124
  return island_borders_list
 
2
  import numpy as np
3
 
4
  class GenerateIslands:
5
+ def __init__(self, indices_color_choices,):
 
 
 
6
  self.indices_color_choices = indices_color_choices
 
7
 
8
  # List of coordinates for each islands border
9
  self.island_borders = {}
 
68
  for cntr_id, contour in enumerate(contours):
69
  area_fraction_perc = (cv.contourArea(contour) / total_area) * 100
70
  if area_fraction_perc >= area_perc_threshold:
71
+ cv.drawContours(contours_image, contours, cntr_id, (0,255,0), 1)
72
 
73
  # If the shape is not valid, return a blank image
74
  return contours_image
 
103
  def get_islands(self, border_padding=2, area_perc_threshold=0.05,
104
  arc_length_area_ratio_threshold=0.1):
105
  for color_index in np.unique(self.indices_color_choices):
 
106
  self._get_islands_for_one_color(
107
  color_index = color_index,
108
  border_padding = border_padding,
 
113
  # Flatten the list of borders
114
  island_borders_list = []
115
  for color_id in self.island_borders:
116
+ island_borders_list += [border_coords for border_coords in self.island_borders[color_id]
117
+ if len(border_coords[1][0]) > 0]
118
 
119
  return island_borders_list