% BLACKSPOT
%
% Function returns a high-pass Butterworth filter centred at position
% (xc,yc) in an image
%
% usage: f = blackspot(im, cutoff, n, xc, yc)
% 
% where: im      is the image for which the filter is to be used on
%        cutoff  is the cut off frequency of the filter 0 - 0.5
%        n       is the order of the filter, the higher n is the sharper
%                the transition is
%        xc,yc   is the desired centre of the filter
function f = blackspot(im, cutoff, n, xc, yc)
    [rows, cols] = size(im);
    
    if cutoff < 0 | cutoff > 0.5
	error('cutoff frequency must be between 0 and 0.5');
    end
    
    if rem(n,1) ~= 0 | n < 1
	error('n must be an integer >= 1');
    end
    
    % X and Y matrices with ranges normalised to +/- 0.5
    x =  (ones(rows,1) * [1:cols]  - (fix(xc)))/cols;
    y =  ([1:rows]' * ones(1,cols) - (fix(yc)))/rows;
    
    radius = sqrt(x.^2 + y.^2);        % A matrix with every pixel = radius relative to centre.
    f
    = 1.0 - ( 1 ./ (1.0 + (radius ./ cutoff).^(2*n)) );   % The filter