sys.path.append('../../../optimaltransport') import numpy as np import matplotlib.pyplot as plt from optrans.continuous import MultiVOT2D from optrans.datasets import adni """ Compute the transport map between two images using the multi-scale variational optimal transport method. Liam Cattell -- May 2018 """ # Load images X, _ = adni.load_data() img0 = adni.load_img0() img1 = X[1] # Multi-scale Variational OT n_scales = 3 vot = MultiVOT2D(n_scales=n_scales, lr=0.01, alpha=0., max_iter=300, verbose=2) img1_hat = vot.forward(img0, img1) # Reconstruct images using transport map img0_recon = vot.apply_forward_map(vot.transport_map_, img1) img1_recon = vot.apply_inverse_map(vot.transport_map_, img0) # Plot cost function for each scale fig1, ax1 = plt.subplots(n_scales, 3) for i, a in enumerate(ax1.reshape((-1, 3))):
import sys sys.path.append('../../../optimaltransport') import numpy as np import matplotlib.pyplot as plt from sklearn.decomposition import PCA from optrans.datasets import adni from optrans.visualization import plot_mode_image """ Perform PCA on image data, and plot a PCA mode of variation as a single image. Liam Cattell -- March 2018 """ # Load some image data X, y = adni.load_data() # Reshape data to be n_imgs-by-n_features n_imgs, h, w = X.shape X = X.reshape((n_imgs, h * w)) # Fit PCA transform pca = PCA(n_components=5) X_pca = pca.fit_transform(X) # Plot mode of variation image ax = plot_mode_image([pca], component=0, shape=(h, w), n_std=3, n_steps=5) plt.show()