% Project 1
% Andy Doran
%
% function out = itrans(in)
%
% in = input image (after being processed with 2D Haar wavelet transform)
% out = original image
%
% This programs takes in an image (in) and outputs the inverse Haar
% Wavelet transform.

function out = itrans(in)

% Get size of input image
[x y] = size(in);
pix = x*y;

% Separate matrix into matrix of sums and matrix of differences
sums = in(:,1:x/2);
diffs = in(:,(x/2)+1:x);

% Put 'in' into an x/2 by 2 matrix, column one is sums and column
% two is diffs, counted off by rows.

sums = sums';
sums = sums(:);
diffs = diffs';
diffs = diffs(:);

new = [sums diffs];

% Multiply by inverse of Haar Wavelet transform
old = new*(inv([1 1;1 -1]/sqrt(2)));

% Put resulting x/2-by-2 matrix into x-by-y matrix, counting off by rows.
old = old';
old = reshape(old,x,y);
out = old';
