This question deals with an example of image reconstruction related to this other question on signal reconstruction. I have different issues in both examples but there could be an underlying factor.
I tried to reconstruct an image using compressed sensing just as in Coursera's course "Computational Methods for Data Analysis" and described in some detail in this pdf (page 414.) By the way, this is the low resolution image:
However, I have a question regarding the reconstruction of the image using $f \approx \Psi x$ where $f$ is the original image, $\Psi$ is a basis (in this case, a discrete cosine transform) to express the image and $x$ its coefficients. This is what I have done, but I'm not entirely sure it's correct.
from PIL import Image from scipy.fftpack import dct, idct from sklearn.linear_model import Lasso # Loading image in grayscale and obtaining its dimensions im = Image.open('coffee-cup.jpg').convert('L') nx, ny = im.shape # Number of sample points used to reconstruct image k = 1000 # Create a permutation from 1 to nx*ny and choose the first k numbers Atest = zeros((nx, ny)).reshape(1, nx*ny) r1 = permutation(arange(1, nx*ny)) r1k = r1[1:k+1] # Suppose the first number in the permutation is 42. Then choose the 42th # elements in a matrix full of zeros and change it to 1. Apply a discrete # cosine transformation to this matrix, and add the result to other matrix # Adelta as a new row. Adelta = zeros((k, nx*ny)) for i, j in enumerate(r1k): Atest[0,j] = 1 Adelta[i, :] = dct(Atest) Atest[0, j] = 0 # Use the same permutation to sample the image to be reconstructed image1 = im.reshape(nx*ny,1) b = image1[r1k] # Solve the optimization problem Adelta * x = b lasso = Lasso(alpha=0.001) lasso.fit(Adelta,b)
After this, lasso.coef_ contains the coefficients $x$. This is the part I'm not sure about. I transformed the coefficients using the discrete cosine transform. However, the construction of Adelta seems to suggest other more elaborated $\Psi$. Yet, when I plot the reconstruction using the inverse discrete cosine transform (IDCT) and the discrete cosine transform (DCT), this is what I get:
recons2 = dct(lasso.coef_).reshape((nx,ny)) recons = idct(lasso.coef_).reshape((nx,ny)) fig = figure() ax = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax.imshow(recons) ax2.imshow(recons2)
It worked reasonably well, but notice that the first image (in which IDCT was used) performed better. I would have assumed that, if something, DCT was more appropriate choice since at least we used the result of a DCT in the construction of Adelta. What is the correct procedure here?