Search code examples
imageimage-processingrecovery

How to recover an image from another given image


If I have a grey-scale, square image (1) and I rotate a copy of it by 90 degrees. I create a new image (2) where the pixels are the sum of the original and rotated images. My question is if I only have image 2 how can I recover the original image 1?


Solution

  • The short answer is: you can't recover the original image.

    Proof:
    Assume 2x2 image:

    I = [a b]
        [c d]
    
    J = I + rot90(I) = [ a + b, b + d] = [E F
                       [ a + c, c + d]    G H]
    

    Now lets try to solve the linear equation system:

    E = a + b + 0 + 0
    F = 0 + b + 0 + d
    G = a + 0 + c + 0
    H = 0 + 0 + c + d
    
    A = [a, b, 0, 0     u = [a   v = [E
         0, b, 0, d          b        F
         a, 0, c, 0          c        G   
         0, 0, c, d]         d]       H]
    
    v = A*u
    

    In order to extract u, matrix A must be invertibale.
    but det(A) = 0, so there are infinite possible solutions.


    I tried an iterative approach.
    I implemented it in MATLAB.

    I played with it a little, and found out that applying bilateral filter, and moderated sharpening, improves the reconstructed result.
    There are probably better heuristics, that I can't think off.

    Here is the MATLAB implementation:

    I = im2double(imread('cameraman.tif'))/2; %Read input sample image and convert to double
    J = I + rot90(I); %Sum of I and rotated I.
    
    %Initial guess.
    I = ones(size(J))*0.5;
    
    h_fig = figure;
    ax = axes(h_fig);
    h = imshow(I/2);
    
    alpha = 0.1;
    beta = 0.01;
    
    %100000 iterations.
    for i = 1:100000
        K = I + rot90(I);
        E = J - K; %E is the error matrix.
        I = I + alpha*E;
    
        if mod(i, 100) == 0
            if (i < 100000*0.9)
                I = imsharpen(imbilatfilt(I), 'Amount', 0.1);
            end
            h.CData = I*2;
            ax.Title.String = num2str(i);
            pause(0.01);
            beta = beta * 0.99;        
        end
    end
    

    Sum of I and rot90(I):
    enter image description here

    Original image:
    enter image description here

    Reconstructed image:
    enter image description here