Exemple #1
0
import numpy as np
import os

import matplotlib.pyplot as plt

from supreme.io import imread
from supreme.noise import dwt_denoise

import demo_data

X = demo_data.chelsea()

noise = np.random.normal(loc=0, scale=30, size=X.shape)
X_ = X + noise
X_ = np.clip(X_, 0, 255)
X_ /= X_.max()

Y = np.clip(dwt_denoise(X_, wavelet='db16', alpha=0.02, levels=4), 0, 255)
Y /= Y.max()

print "MSE:", np.mean((X - Y)**2)/np.prod(X.shape)

plt.subplot(2, 2, 1)
plt.imshow(X)
plt.title('Input Image')

plt.subplot(2, 2, 2)
plt.imshow(X_)
plt.title('Severe Noise Added')

plt.subplot(2, 2, 3)
Exemple #2
0
import numpy as np

from demo_data import chelsea
from supreme.register.parzen import joint_hist, mutual_info
from supreme.transform import homography

import matplotlib.pyplot as plt

h1 = chelsea(grey=True).astype(np.uint8)
plt.suptitle('Parzen-Window Joint PDF Estimator')

for n, t in enumerate([0, 0.01, 0.1]):
    plt.subplot(1, 3, n + 1)

    h2 = homography(h1, [[np.cos(t), -np.sin(t), 0],
                         [np.sin(t),  np.cos(t), 0],
                         [0,            0,       1]])

    if n == 0:
        plt.ylabel('Grey levels in A')
        plt.xlabel('Grey levels in B')

    H = joint_hist(h1, h2, win_size=5, std=1)
    S = mutual_info(H)

    plt.title('Rotation $%.2f^\\circ$\nS=%.5f' % ((t / np.pi * 180), S))

    plt.imshow(np.log(H + 10), interpolation='nearest')

plt.show()
Exemple #3
0
import numpy as np

from demo_data import chelsea
from supreme.register.parzen import joint_hist, mutual_info
from supreme.transform import homography
import supreme.register as register

import sys
if len(sys.argv) == 3:
    from supreme.io import imread
    A = imread(sys.argv[1], flatten=True).astype(np.uint8)
    Ac = imread(sys.argv[1], flatten=False).astype(np.uint8)
    B = imread(sys.argv[2], flatten=True).astype(np.uint8)
    Bc = imread(sys.argv[2], flatten=False).astype(np.uint8)
else:
    A = chelsea(grey=True).astype(np.uint8)
    Ac = A
    t = 20 / 180. * np.pi
    x = 3
    y = 6
    B = homography(
        A, [[np.cos(t), -np.sin(t), x], [np.sin(t), np.cos(t), y], [0, 0, 1]])
    Bc = B

M, S = register.dense_MI(A, B, levels=3, std=5, win_size=9)
print "Mutual information: ", S
if S < 1.5:
    print "Warning: registration probably failed."

print "Transformation matrix:"
print np.array2string(M, separator=', ')