From 062071b20d1d40c64bb619931bd11bd28e780485 Mon Sep 17 00:00:00 2001 From: RĂ©mi Flamary Date: Fri, 1 Sep 2017 15:31:44 +0200 Subject: update example with rst titles --- .../source/auto_examples/plot_otda_color_images.py | 66 +++++++++++----------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'docs/source/auto_examples/plot_otda_color_images.py') diff --git a/docs/source/auto_examples/plot_otda_color_images.py b/docs/source/auto_examples/plot_otda_color_images.py index 46ad44b..f1df9d9 100644 --- a/docs/source/auto_examples/plot_otda_color_images.py +++ b/docs/source/auto_examples/plot_otda_color_images.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -======================================================== -OT for domain adaptation with image color adaptation [6] -======================================================== +============================= +OT for image color adaptation +============================= This example presents a way of transferring colors between two image with Optimal Transport as introduced in [6] @@ -41,7 +41,7 @@ def minmax(I): ############################################################################## -# generate data +# Generate data ############################################################################## # Loading images @@ -61,33 +61,7 @@ Xt = X2[idx2, :] ############################################################################## -# Instantiate the different transport algorithms and fit them -############################################################################## - -# EMDTransport -ot_emd = ot.da.EMDTransport() -ot_emd.fit(Xs=Xs, Xt=Xt) - -# SinkhornTransport -ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) -ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - -# prediction between images (using out of sample prediction as in [6]) -transp_Xs_emd = ot_emd.transform(Xs=X1) -transp_Xt_emd = ot_emd.inverse_transform(Xt=X2) - -transp_Xs_sinkhorn = ot_emd.transform(Xs=X1) -transp_Xt_sinkhorn = ot_emd.inverse_transform(Xt=X2) - -I1t = minmax(mat2im(transp_Xs_emd, I1.shape)) -I2t = minmax(mat2im(transp_Xt_emd, I2.shape)) - -I1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) -I2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape)) - - -############################################################################## -# plot original image +# Plot original image ############################################################################## pl.figure(1, figsize=(6.4, 3)) @@ -104,7 +78,7 @@ pl.title('Image 2') ############################################################################## -# scatter plot of colors +# Scatter plot of colors ############################################################################## pl.figure(2, figsize=(6.4, 3)) @@ -126,7 +100,33 @@ pl.tight_layout() ############################################################################## -# plot new images +# Instantiate the different transport algorithms and fit them +############################################################################## + +# EMDTransport +ot_emd = ot.da.EMDTransport() +ot_emd.fit(Xs=Xs, Xt=Xt) + +# SinkhornTransport +ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) +ot_sinkhorn.fit(Xs=Xs, Xt=Xt) + +# prediction between images (using out of sample prediction as in [6]) +transp_Xs_emd = ot_emd.transform(Xs=X1) +transp_Xt_emd = ot_emd.inverse_transform(Xt=X2) + +transp_Xs_sinkhorn = ot_emd.transform(Xs=X1) +transp_Xt_sinkhorn = ot_emd.inverse_transform(Xt=X2) + +I1t = minmax(mat2im(transp_Xs_emd, I1.shape)) +I2t = minmax(mat2im(transp_Xt_emd, I2.shape)) + +I1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) +I2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape)) + + +############################################################################## +# Plot new images ############################################################################## pl.figure(3, figsize=(8, 4)) -- cgit v1.2.3