function im_deblur = InverseMartin(im, len, angle)

% Restores Image Using Inverse Filter
%
% im_deblur = InverseMartin(im, len, angle)
%
% Inputs: im, len, angle
% Returns: im_deblur
%
% im:    Input Image
% angle: Blur Angle (Degrees) 
% len:   Blur Length (Number of Pixels)
%
% im_deblur: Restored Image

% Performing Median Filtering 
im = medfilt2(abs(im));

% Convert to Frequency Domain
IM = fft2(im);

% Create PSF of Blur
psf = fspecial('motion',len,angle);

% Convert psf to OTF
OTF = psf2otf(psf,size(IM));

% Find Maximum Value in OTF
max = max2(OTF); % Function max2 is not a built in MATLAB function

% Pin Minimum Values to 5% of Max
for i = 1:size(OTF, 1)
    for j = 1:size(OTF, 2)
        if OTF(i, j) <= 0.05*max
            OTF(i, j) = 0.05*max;
        end
    end
end

% Deblurring Image with Inverse Filter
debl = IM./OTF;

% Restored Image
im_deblur = ifft2(debl);