def _plot_image(working_dir, axis, point_img, colour, output_directory, plot_name): axis = ImageObject(load_image(f"{working_dir}/{axis}", 4)) blank = axis.blank_like(True) print(f"Processing {plot_name} -> {point_img}: {colour}") # Load the point image point_img = ImageObject(load_image(f"{working_dir}/{point_img}", 4)) # Create the overlay colour overlay_colour = point_img.blank_like(True) overlay_colour.change_bgra_to_bgr() overlay_colour.change_a_colour((0, 0, 0), colour) # Set the point mask point_mask = point_img.mask_alpha(True) point_mask.change_bgra_to_bgr() point_mask.change_to_mono() # Mask the colour on the point mask then assign it the point masks alpha channel overlay_colour.mask_on_image(point_mask) overlay_colour.change_bgr_to_bgra() overlay_colour.assign_alpha_channel(point_mask) blank.overlay_additive(overlay_colour) blank.overlay_additive(axis) blank.write_to_file(output_directory, plot_name)
def create_heat_map_frames(working_directory, point_colour, point_out, gradient_out, gradient_scalar, gradient_divider): dates = {"".join([n.replace(".png", "").zfill(2) for n in name.split("_")]): name for name in directory_iterator(working_directory)} # Format dates to be sorted dates = {date: name for date, name in sorted(dates.items(), key=lambda kv: kv[0])} # Create the bound to mask on, the isolate the first frame base = _base_image(dates, working_directory) bound_min = (max(point_colour[0]-5, 0), max(point_colour[1]-5, 0), max(point_colour[2]-5, 0)) base.mask_on_colour_range(bound_min, point_colour) # Point frames for index, (date, name) in enumerate(dates.items()): if index % 10 == 0: print(f"Frame {index}: {len(dates.items())}") if index > 0: current_date = ImageObject(load_image(str(Path(working_directory, name).absolute()))) current_date.mask_on_colour_range(bound_min, point_colour) current_date.write_to_file(point_out, index) # Gradient frames for index, (date, name) in enumerate(dates.items()): if index % 10 == 0: print(f"Frame {index}: {len(dates.items())}") if index > 0: difference = _create_difference(working_directory, name, bound_min, point_colour, base, gradient_scalar, gradient_divider) difference.write_to_file(gradient_out, index) base = difference
def _create_difference(working_directory, name, bound_min, point_colour, base, gradient_scalar, gradient_divider): current_date = ImageObject(load_image(str(Path(working_directory, name).absolute()))) current_date.mask_on_colour_range(bound_min, point_colour) return ImageObject(((base.image * gradient_scalar) + current_date.image) / gradient_divider)
def _base_image(dates_dict, read_directory): for date, name in dates_dict.items(): return ImageObject(load_image(str(Path(read_directory, name).absolute())))
def _construct_plot_image(working_dir, axis, points, colours, output_directory, plot_name): axis = ImageObject(load_image(f"{working_dir}/{axis}", 4)) blank = axis.blank_like(True) for point_img, colour in zip(points, colours): print(f"Processing {plot_name} -> {point_img}: {colour}") # Load the point image point_img = ImageObject(load_image(f"{working_dir}/{point_img}", 4)) # Create the overlay colour overlay_colour = point_img.blank_like(True) overlay_colour.change_bgra_to_bgr() overlay_colour.change_a_colour((0, 0, 0), colour) # Set the point mask point_mask = point_img.mask_alpha(True) point_mask.change_bgra_to_bgr() point_mask.change_to_mono() # Mask the colour on the point mask then assign it the point masks alpha channel overlay_colour.mask_on_image(point_mask) overlay_colour.change_bgr_to_bgra() overlay_colour.assign_alpha_channel(point_mask) blank.overlay_additive(overlay_colour) blank.overlay_additive(axis) blank.write_to_file(output_directory, plot_name) # a = ImageObject(load_image(r"/Tests/ManhattanTests/untitled.png", 4)) # print(a) # # # c = a.blank_like(True) # c.change_bgra_to_bgr() # # # b = a.mask_alpha(True) # # b.change_bgra_to_bgr() # b.change_to_mono() # # c.change_a_colour((0, 0, 0), (160, 80, 0)) # # c.mask_on_image(b) # # # a.change_bgra_to_bgr() # # a.overlay_image(c, 0, 0) # # a.change_bgr_to_bgra() # # a.assign_alpha_channel(b) # # # print(type(rgba)) # # # # b.show() # # # # cv2.imwrite(r"C:\Users\Samuel\PycharmProjects\pyBlendFigures\Tests\ManhattanTests\Name2.png", rgba) # # a.write_to_file(r"C:\Users\Samuel\PycharmProjects\pyBlendFigures\Tests\ManhattanTests", "Plot2")