In [1]:
%matplotlib inline
import numpy as np
from scipy import ndimage
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from model import OrderExtend
img = ndimage.imread('images/boat.jpeg', flatten=True)
img /= np.max(img) #normalize image [0,1]
plt.imshow(img, cmap = cm.Greys_r)
Out[1]:
In [2]:
nx,ny = img.shape
r = 50
p = 0.3
max_iter = 100
theta = 1
# mask of the observed pixels (randomly chosen)
sigma = np.random.binomial(1, p, size=img.shape)
model = OrderExtend(img, sigma, r, theta=theta)
order = model.init()
r_img, x, y = model.fit(order, max_iter=max_iter)
plt.imshow(r_img, cmap = cm.Greys_r)
print(np.max(r_img),np.min(r_img))
Now we set the iteration number to 1000, and rerun the model.
In [3]:
r_img, x, y = model.fit(order, max_iter=1000)
plt.imshow(r_img, cmap = cm.Greys_r)
print(np.max(r_img),np.min(r_img))
In [4]:
#set the threshold to 3
theta = 3
nx,ny = img.shape
r = 50
p = 0.3
max_iter = 5000
# mask of the observed pixels (randomly chosen)
sigma = np.random.binomial(1, p, size=img.shape)
# initialize another model with new theta
model = OrderExtend(img, sigma, r, theta)
order = model.init()
r_img, x, y = model.fit(order, max_iter=max_iter)
plt.imshow(r_img, cmap = cm.Greys_r)
Out[4]:
In [5]:
print(np.max(r_img), np.min(r_img))