Spaces:
Runtime error
Runtime error
Sagar Bharadwaj commited on
Commit ·
d2ae102
1
Parent(s): 342535f
Updated docstrings
Browse filesFiles changed (4)
1234567891011121314151617181920212223242526default_config = { # If True, the image will be denoised after simplification. "denoise": True,
# Higher values will result in more aggressive denoising. "denoise_h": 100,
# Padding around the borders of the image. "border_padding": 2,
# Color islands with area less than this threshold will be ignored. # The value is a percentage of the total area of the image. "area_perc_threshold": 0.05,
# If True, all shapes with perimeter to area ratio of less than # arc_length_area_ratio_threshold will be ignored. "check_shape_validity": True, "arc_length_area_ratio_threshold": 1,
# Color of the border around around color islands. "border_color": (0, 0, 0),
# Font for the numbers shown in color islands. "font_size": 0.5, "font_color": (0, 0, 0), "font_thickness": 2,5 unmodified lines6789910111213141516175 unmodified lines
class GenerateIslands: def __init__(self, indices_color_choices,): def __init__(self, indices_color_choices): """ Args: indices_color_choices: 2D numpy array with the same shape as the image. Shows the color index chosen for each pixel in the image. """ self.indices_color_choices = indices_color_choices # List of coordinates for each islands border7 unmodified lines891011121314151617181939 unmodified lines5960615657585960616263646566676869707172737 unmodified lines
class ColorByNumber: def __init__(self, image_path, color_list, config = default_config): """ Args: image_path: Path to the image file. color_list: List of colors in (R, G, B) format. config: Dictionary of configuration parameters (optional). """ self.image_path = image_path self.color_list = color_list self.config = config39 unmodified lines Generates a grid of colored squares with labels below them.
Args: colors: List of colors in (R, G, B) format. rows: Number of rows in the grid (optional). cols: Number of columns in the grid (optional).
Returns: A NumPy array representing the color grid image. cols: Number of columns in the grid. rows: Number of rows in the grid. square_size: Size of each square in the grid. margin: Margin around the grid. gap_horizontal: Horizontal gap between squares. gap_vertical: Vertical gap between squares. font: Font for the labels. font_size: Font size for the labels. border_color: Color of the border around each square. """
# Calculate grid dimensions if not provided18 unmodified lines1920212223242519 unmodified lines454647474849505149505152535455565732 unmodified lines9091929091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612718 unmodified lines position (tuple): The position to add the text. font_size (int): The size of the font. font_color (tuple): The color of the font. font_thickness (int): The thickness of the font. Returns: np.array: A new image with the text added. """19 unmodified lines """Create a new image with the islands numbered. Args: image (np.array): Numpy image. islands (list): A list of tuples. Each tuple contains the color_id and the coordinates of the pixels in an island. Returns: np.array: A new image with the islands numbered. Each tuple contains the color id and the coordinates of the island border. image_shape (tuple): The shape of the original image. centroid_coords_list (list): A list of centroid coordinates for the islands. config (dict): Configuration dictionary. show_numbers (bool): If True, the numbers will be shown in the islands. binary (bool): If True, the output will be a binary image. """
padding = config["border_padding"]32 unmodified lines return numbered_islands
return numbered_islands
def _test_create_numbered_islands(): image_shape = (853, 1280, 3)
max_row, max_col = image_shape[0], image_shape[1]
diagonal_coordinates = [ (i,i) for i in range(max_row) ] left_border = [ (i, 0) for i in range(max_row) ] bottom_border_left = [ (max_row-1, i) for i in range(max_row) ] region_1 = diagonal_coordinates + left_border + bottom_border_left
bottom_border_right = [ (max_row - 1, i) for i in range(max_row, max_col) ] right_border = [ (i, max_col - 1) for i in range(max_row) ] top_border = [ (0, i) for i in range(max_col) ] region_2 = bottom_border_right + right_border + top_border
numbered_islands = create_numbered_islands( islands = [ ('random_color_1', region_1), ('random_color_2', region_2) ], image_shape = image_shape, )
return numbered_islandscolorbynumber/config.py+15
colorbynumber/gen_islands.py+6-1
colorbynumber/main.py+15-6
colorbynumber/numbered_islands.py+7-42