function [angle, len] = estblur(im);

% Blur Parameter Estimator
%
% [angle, len] = estblur(im)
%
% Inputs: im
% Returns: angle, len
%
% im:    Input Image
%
% angle: Blur Angle (Degrees) 
% len:   Blur Length (Number of Pixels)

% Calculate Cepstrum 

IM = abs(fft2(im));

lg = log(1 + IM);

lgpow = abs(lg).^2;

% Cepstrum
lgcep = ifftshift(ifft2(lgpow)); 

% Size
slgcep = size(lgcep);

% Find Min Values of Cepstrum to 
% Obtain Length and Angle of Blur

% Select Right Side of Cepstrum 
% (Cepstrum is Symmetric, Simplifies min Finding)
lgcep2 = lgcep(:,[slgcep(2)/2 + 1 : slgcep(2)]);
% Size
slgcep2 = size(lgcep2);

% Column min
min_col = min(real(lgcep2));
[val_col, ind_col] = min(min_col);

% Row min
min_row = min(imrotate(real(lgcep2),90));
[val_row, ind_row] = min(min_row);

% Convert to Distance from Origin
x_dist = ind_col;
y_dist = (slgcep2(1)/2 + 1) - ind_row;

% Blur Length
len = round( sqrt( x_dist^2 + y_dist^2 ) - 1 );

% Blur Angle
angle = round( atan( y_dist / x_dist ) * (180/pi) );