img1 = signal_to_pdf(img1, sigma=6.)

# Compute the Radon-CDT of img1 w.r.t. img0
radoncdt = RadonCDT()
rcdt = radoncdt.forward(img0, img1)

# Get the domain of our signal
x = radoncdt.transport_map_ + radoncdt.displacements_

# Get min/max intensities for plotting purposes
vmin = img0.min()
vmax = img0.max()

# Plot linear interpolation in signal space and Radon-CDT space
fig, ax = plt.subplots(2, 5, figsize=(10,6))
for i,alpha in enumerate(np.linspace(0, 1, 5)):
    # Interpolation in image space
    img_interp = (1. - alpha) * img0 + alpha * img1
    ax[0,i].imshow(img_interp, vmin=vmin, vmax=vmax)
    ax[0,i].set_title('alpha = {:.2f}'.format(alpha))

    # Interpolation in Radon-CDT space
    u = radoncdt.displacements_ * alpha
    f = x - u
    img_recon = radoncdt.apply_inverse_map(f, img0)
    ax[1,i].imshow(img_recon, vmin=vmin, vmax=vmax)

ax[0,0].set_ylabel('Image space')
ax[1,0].set_ylabel('Radon-CDT space')
plt.show()
Ejemplo n.º 2
0
# Select two patches to be our sample images
img0 = img[50:162, 70:134]
img1 = img[32:144, 64:128]

# Convert images to PDFs
img0 = signal_to_pdf(img0, sigma=1.)
img1 = signal_to_pdf(img1, sigma=1.)

# Compute Radon-CDT of img1 w.r.t img0
theta = np.arange(0, 179, 2)
radoncdt = RadonCDT(theta=theta)
img1_hat = radoncdt.forward(img0, img1)

# Apply transport map in order to reconstruct images
img0_recon = radoncdt.apply_forward_map(radoncdt.transport_map_, img1)
img1_recon = radoncdt.apply_inverse_map(radoncdt.transport_map_, img0)
# img1_recon = radoncdt.inverse()

fig, ax = plt.subplots(3, 2)
ax[0, 0].imshow(img0)
ax[0, 0].set_title('Reference img0')
ax[0, 1].imshow(img1)
ax[0, 1].set_title('Image img1')
ax[1, 0].imshow(img0_recon)
ax[1, 0].set_title('Reconstructed img0')
ax[1, 1].imshow(img1_recon)
ax[1, 1].set_title('Reconstructed img1')
ax[2, 0].imshow(radoncdt.displacements_)
ax[2, 0].set_title('Displacements u')
ax[2, 1].imshow(img1_hat)
ax[2, 1].set_title('Radon-CDT')
Ejemplo n.º 3
0
ind = 0
n_std = 2.
n_steps = 5
mode = get_mode_variation(pca, component=ind, n_std=n_std, n_steps=n_steps)

# Initialise Radon-CDT so we can compute inverse transform
radoncdt = RadonCDT()

# Get std dev. along component
std = np.sqrt(pca.explained_variance_[ind])
std_range = np.linspace(-n_std / 2, n_std / 2, n_steps)

# Plot mode of variation
fig2, ax2 = plt.subplots(1, n_steps)
for m, s, a in zip(mode, std_range, ax2):
    img_recon = radoncdt.apply_inverse_map(m.reshape((h, w)), img0)
    a.imshow(img_recon)
    a.set_title("{:.2f}$\sigma$".format(s))

# Get histogram of data projected on to component
hist, bin_centers = get_mode_histogram(X_pca / std,
                                       y,
                                       component=ind,
                                       bins=7,
                                       range=(std_range[0], std_range[-1]))
wid = (bin_centers[0] - bin_centers[1]) / 2

# Plot histogram
fig3, ax3 = plt.subplots(1, 1)
ax3.bar(bin_centers, hist, width=wid)
ax3.set_title('Data projected on to component {}'.format(ind))