import matplotlib.image as mpimg
import matplotlib.pylab as plt
import numpy as np
%matplotlib inline

im = mpimg.imread("data/monalisa.jpg")

plt.imshow(im)
plt.show()
im.shape

"""
Explanation: Assignment 1: Pixel Regression.
Can we recover an image by learning a deep regression map from pixels $(x,y)$ to colors $(r,g,b)$?
Our target image will be Mona Lisa:
End of explanation
"""


X_train = []
Y_train = []
for i in range(im.shape[0]):
    for j in range(im.shape[1]):
        X_train.append([float(i),float(j)])
        Y_train.append(im[i][j])
        
X_train = np.array(X_train)
Y_train = np.array(Y_train)
print 'Samples:', X_train.shape[0]
print '(x,y):', X_train[0],'\n', '(r,g,b):',Y_train[0]

"""
Explanation: Ourt training dataset will be composed of pixels locatiions and input and pixel values as output:
End of explanation
"""


import keras
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout

# your model here
# hints: k*10^2 neurons per layer + good initialization + deep network (>2 layers)



# use this cell to find the best model architecture

model.fit(X_train, Y_train, nb_epoch=1, shuffle=True, verbose=1, batch_size=10)
Y = model.predict(X_train, batch_size=10000)
k = 0
im_out = im[:]
for i in range(im.shape[0]):
    for j in range(im.shape[1]):
        im_out[i,j]= Y[k]
        k += 1
        
plt.imshow(im_out)
plt.show()

"""
Explanation: Our objective is to train a deep MLP that is able to reconstruct the image:
End of explanation
"""


