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 labSliceAnimation(): 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("Lab slice (Animation)", fontsize=font_size) plt.subplot(1, 2, 1) plt.title("OpenCV Lab2rgb", fontsize=font_size) lab_plot_cv = LabSlicePlot(LabSlice(func=Lab2rgb_cv)) plt.subplot(1, 2, 2) plt.title("Implemented Lab2rgb", fontsize=font_size) lab_plot_py = LabSlicePlot(LabSlice(func=Lab2rgb_py)) def animFunc(step, *args): plots = lab_plot_cv.animationFunc(step) plots.extend(lab_plot_py.animationFunc(step)) plt.draw() return plots ani = animation.FuncAnimation(fig, animFunc, interval=0, blit=True) showMaximize()
def __init__(self, abs_original, abs_edited, L=50, abs_animation=[]): self._slice = LabSlice(func=Lab2rgb_py) self._slice_plot = LabSlicePlot(self._slice) self._slice_plot.plot(L) self._abs_original = abs_original self._abs_edited = abs_edited self._abs_animation = abs_animation self._transfer = ABTransfer(abs_original, abs_edited) self._plot()
class ABTransferPlot: ## Constructor # @param abs_original original ab coordinates. # @param abs_edited edited ab coordinates. # @param L target L coordinate. # @param abs_animation list of ab coordinates for plot animation. def __init__(self, abs_original, abs_edited, L=50, abs_animation=[]): self._slice = LabSlice(func=Lab2rgb_py) self._slice_plot = LabSlicePlot(self._slice) self._slice_plot.plot(L) self._abs_original = abs_original self._abs_edited = abs_edited self._abs_animation = abs_animation self._transfer = ABTransfer(abs_original, abs_edited) self._plot() ## Animation function for matplot. def animationFunc(self, step, *args): ab_id = step % len(self._abs_animation) ab_original = self._abs_animation[ab_id] xy_original, xy_edited = self._blendResult(ab_original) self._setArrow(self._blend_plot, xy_original, xy_edited) return self._blend_plot def _plot(self): xys_original = [self._slice.ab2xy(ab_original) for ab_original in self._abs_original] xys_edited = [self._slice.ab2xy(ab_edited) for ab_edited in self._abs_edited] for xy_original, xy_edited in zip(xys_original, xys_edited): self._arrow(xy_original, xy_edited) xy_original, xy_edited = self._blendResult(self._abs_animation[0]) self._blend_plot = self._arrow(xy_original, xy_edited, color=[0.7, 0.5, 0.4]) def _arrow(self, ps, pe, color=[1, 1, 1]): xs = [ps[0], pe[0]] ys = [ps[1], pe[1]] return [ plt.plot(xs, ys, "-", color=color, linewidth=2, alpha=0.8)[0], plt.plot(ps[0], ps[1], "o", color=color, linewidth=2, alpha=0.8)[0], ] def _setArrow(self, arrow_plot, ps, pe): xs = [ps[0], pe[0]] ys = [ps[1], pe[1]] arrow_plot[0].set_data(xs, ys) arrow_plot[1].set_data(ps[0], ps[1]) def _blendResult(self, ab_original): ab_edited = self._transfer.transfer(ab_original) xy_original = self._slice.ab2xy(ab_original) xy_edited = self._slice.ab2xy(ab_edited) return xy_original, xy_edited
class ABTransferPlot: ## Constructor # @param abs_original original ab coordinates. # @param abs_edited edited ab coordinates. # @param L target L coordinate. # @param abs_animation list of ab coordinates for plot animation. def __init__(self, abs_original, abs_edited, L=50, abs_animation=[]): self._slice = LabSlice(func=Lab2rgb_py) self._slice_plot = LabSlicePlot(self._slice) self._slice_plot.plot(L) self._abs_original = abs_original self._abs_edited = abs_edited self._abs_animation = abs_animation self._transfer = ABTransfer(abs_original, abs_edited) self._plot() ## Animation function for matplot. def animationFunc(self, step, *args): ab_id = step % len(self._abs_animation) ab_original = self._abs_animation[ab_id] xy_original, xy_edited = self._blendResult(ab_original) self._setArrow(self._blend_plot, xy_original, xy_edited) return self._blend_plot def _plot(self): xys_original = [ self._slice.ab2xy(ab_original) for ab_original in self._abs_original ] xys_edited = [ self._slice.ab2xy(ab_edited) for ab_edited in self._abs_edited ] for xy_original, xy_edited in zip(xys_original, xys_edited): self._arrow(xy_original, xy_edited) xy_original, xy_edited = self._blendResult(self._abs_animation[0]) self._blend_plot = self._arrow(xy_original, xy_edited, color=[0.7, 0.5, 0.4]) def _arrow(self, ps, pe, color=[1, 1, 1]): xs = [ps[0], pe[0]] ys = [ps[1], pe[1]] return [ plt.plot(xs, ys, '-', color=color, linewidth=2, alpha=0.8)[0], plt.plot(ps[0], ps[1], 'o', color=color, linewidth=2, alpha=0.8)[0] ] def _setArrow(self, arrow_plot, ps, pe): xs = [ps[0], pe[0]] ys = [ps[1], pe[1]] arrow_plot[0].set_data(xs, ys) arrow_plot[1].set_data(ps[0], ps[1]) def _blendResult(self, ab_original): ab_edited = self._transfer.transfer(ab_original) xy_original = self._slice.ab2xy(ab_original) xy_edited = self._slice.ab2xy(ab_edited) return xy_original, xy_edited