2222import matplotlib .pylab as pl
2323import ot
2424
25- np .random .seed (42 )
25+
26+ r = np .random .RandomState (42 )
2627
2728
2829def im2mat (I ):
@@ -39,6 +40,10 @@ def minmax(I):
3940 return np .clip (I , 0 , 1 )
4041
4142
43+ ##############################################################################
44+ # generate data
45+ ##############################################################################
46+
4247# Loading images
4348I1 = ndimage .imread ('../../data/ocean_day.jpg' ).astype (np .float64 ) / 256
4449I2 = ndimage .imread ('../../data/ocean_sunset.jpg' ).astype (np .float64 ) / 256
@@ -48,12 +53,17 @@ def minmax(I):
4853
4954# training samples
5055nb = 1000
51- idx1 = np . random .randint (X1 .shape [0 ], size = (nb ,))
52- idx2 = np . random .randint (X2 .shape [0 ], size = (nb ,))
56+ idx1 = r .randint (X1 .shape [0 ], size = (nb ,))
57+ idx2 = r .randint (X2 .shape [0 ], size = (nb ,))
5358
5459Xs = X1 [idx1 , :]
5560Xt = X2 [idx2 , :]
5661
62+
63+ ##############################################################################
64+ # Instantiate the different transport algorithms and fit them
65+ ##############################################################################
66+
5767# EMDTransport
5868ot_emd = ot .da .EMDTransport ()
5969ot_emd .fit (Xs = Xs , Xt = Xt )
@@ -75,6 +85,7 @@ def minmax(I):
7585I1te = minmax (mat2im (transp_Xs_sinkhorn , I1 .shape ))
7686I2te = minmax (mat2im (transp_Xt_sinkhorn , I2 .shape ))
7787
88+
7889##############################################################################
7990# plot original image
8091##############################################################################
@@ -91,6 +102,7 @@ def minmax(I):
91102pl .axis ('off' )
92103pl .title ('Image 2' )
93104
105+
94106##############################################################################
95107# scatter plot of colors
96108##############################################################################
@@ -112,6 +124,7 @@ def minmax(I):
112124pl .title ('Image 2' )
113125pl .tight_layout ()
114126
127+
115128##############################################################################
116129# plot new images
117130##############################################################################
0 commit comments