def labSliceVideo(): fig = plt.figure(figsize=(12, 6)) fig.subplots_adjust(left=0.1, bottom=0.05, right=0.9, top=0.9, wspace=0.3, hspace=0.2) font_size = 15 fig.suptitle("Lab slice (Animation)", fontsize=font_size) plt.subplot(1, 2, 1) plt.title("OpenCV Lab2rgb", fontsize=font_size) num_slices = 101 lab_plot_cv = LabSlicePlot(LabSlice(func=Lab2rgb_cv), num_slices=num_slices) plt.subplot(1, 2, 2) plt.title("Implemented Lab2rgb", fontsize=font_size) lab_plot_py = LabSlicePlot(LabSlice(func=Lab2rgb_py), num_slices=num_slices) def animFunc(step, *args): lab_plot_cv.animationFunc(step) lab_plot_py.animationFunc(step) return figure2numpy(fig) images = [animFunc(step) for step in range(2 * num_slices)] result_file = resultFile("LabSlice", ".wmv") saveVideo(result_file, images)
def singleImageResult(image_file): image_name = os.path.basename(image_file) image_name = os.path.splitext(image_name)[0] image = loadRGB(image_file) fig = plt.figure(figsize=(10, 7)) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.9, wspace=0.1, hspace=0.2) font_size = 15 fig.suptitle("Palette Selection for Single Image", fontsize=font_size) fig.add_subplot(231) h, w = image.shape[:2] plt.title("Original Image: %s x %s" % (w, h), fontsize=font_size) plt.imshow(image) plt.axis('off') color_spaces = ["rgb", "Lab"] sigmas = [0.7, 70.0] plot_id = 232 num_cols = 3 for color_space, sigma in zip(color_spaces, sigmas): hist3D = Hist3D(image, num_bins=16, color_space=color_space) color_coordinates = hist3D.colorCoordinates() color_densities = hist3D.colorDensities() rgb_colors = hist3D.rgbColors() palette_selection = PaletteSelection(color_coordinates, color_densities, rgb_colors, num_colors=5, sigma=sigma) plt.subplot(plot_id) plt.title("Palette Colors from %s" % color_space) palette_selection.plot(plt) plt.axis('off') plot_id += 1 ax = fig.add_subplot(plot_id, projection='3d') plt.title("%s 3D Histogram" % color_space, fontsize=font_size) hist3D.plot(ax) plot_id += num_cols - 1 result_file = resultFile("%s_single" % image_name) plt.savefig(result_file)
def colorTransferVideo(figsize=(12, 6)): fig = plt.figure() fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.9, wspace=0.1, hspace=0.2) font_size = 15 fig.suptitle("Color Transfer (Animation)", fontsize=font_size) ab_original = [(-10, -20), (-20, 10), (40, 20)] ab_edited = [(30, -50), (10, 30), (60, -20)] abs_points = [(0, 0), (-20, 10), (0, -30), (-20, 10), (-20, 20), (40, 20), (40, -10)] abs_animation = resample(abs_points, num=100) transfer_plot = ABTransferPlot(ab_original, ab_edited, abs_animation=abs_animation) def animFunc(step, *args): transfer_plot.animationFunc(step) return figure2numpy(fig) images = [animFunc(step) for step in range(2*len(abs_animation))] result_file = resultFile("ColorTransfer", ".wmv") saveVideo(result_file, images)
def labSliceVideo(): fig = plt.figure(figsize=(12, 6)) fig.subplots_adjust(left=0.1, bottom=0.05, right=0.9, top=0.9, wspace=0.3, hspace=0.2) font_size = 15 fig.suptitle("Lab slice (Animation)", fontsize=font_size) plt.subplot(1, 2, 1) plt.title("OpenCV Lab2rgb", fontsize=font_size) num_slices = 101 lab_plot_cv = LabSlicePlot(LabSlice(func=Lab2rgb_cv), num_slices=num_slices) plt.subplot(1, 2, 2) plt.title("Implemented Lab2rgb", fontsize=font_size) lab_plot_py = LabSlicePlot(LabSlice(func=Lab2rgb_py), num_slices=num_slices) def animFunc(step, *args): lab_plot_cv.animationFunc(step) lab_plot_py.animationFunc(step) return figure2numpy(fig) images = [animFunc(step) for step in range(2*num_slices)] result_file = resultFile("LabSlice", ".wmv") saveVideo(result_file, images)
def multiImagesResult(data_name, data_ids): num_cols = len(data_ids) num_rows = 2 fig = plt.figure(figsize=(10, 7)) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.9, wspace=0.1, hspace=0.2) font_size = 15 fig.suptitle("Palette Selection for Multi Images", fontsize=font_size) rgb_pixels = [] plot_id = num_rows * 100 + 10 * num_cols + 1 for data_id in data_ids: image_file = dataFile(data_name, data_id) image = loadRGB(image_file) rgb_pixels.extend(ColorPixels(image).rgb()) fig.add_subplot(plot_id) h, w = image.shape[:2] plt.title("Original Image: %s x %s" % (w, h), fontsize=font_size) plt.imshow(image) plt.axis('off') plot_id += 1 color_space = "Lab" sigma = 70.0 plot_id = num_rows * 100 + 10 * num_cols + num_cols + 2 rgb_pixels = np.array(rgb_pixels) multi_image = np.array(rgb_pixels).reshape(1, -1, 3) hist3D = Hist3D(multi_image, num_bins=16, color_space=color_space) color_coordinates = hist3D.colorCoordinates() color_densities = hist3D.colorDensities() rgb_colors = hist3D.rgbColors() palette_selection = PaletteSelection(color_coordinates, color_densities, rgb_colors, num_colors=5, sigma=sigma) plt.subplot(plot_id) plt.title("Palette Colors from %s" % color_space) palette_selection.plot(plt) plt.axis('off') plot_id += 1 ax = fig.add_subplot(plot_id, projection='3d') plt.title("%s 3D Histogram" % color_space, fontsize=font_size) hist3D.plot(ax) result_file = resultFile("%s_multi" % data_name) plt.savefig(result_file)