Content Based Image Retrieval
30 May 2013
(Updated 29 Aug 2013)
Simple content based image retrieval for demonstration purposes. Either using knn or classification
% LOWPASSFILTER - Constructs a low-pass butterworth filter.
% usage: f = lowpassfilter(sze, cutoff, n)
% where: sze is a two element vector specifying the size of filter
% to construct [rows cols].
% cutoff is the cutoff frequency of the filter 0 - 0.5
% n is the order of the filter, the higher n is the sharper
% the transition is. (n must be an integer >= 1).
% Note that n is doubled so that it is always an even integer.
% f = --------------------
% 1.0 + (w/cutoff)
% The frequency origin of the returned filter is at the corners.
function f = lowpassfilter(sze, cutoff, n)
if cutoff < 0 | cutoff > 0.5
error('cutoff frequency must be between 0 and 0.5');
if rem(n,1) ~= 0 | n < 1
error('n must be an integer >= 1');
if length(sze) == 1
rows = sze; cols = sze;
rows = sze(1); cols = sze(2);
% Set up X and Y matrices with ranges normalised to +/- 0.5
% The following code adjusts things appropriately for odd and even values
% of rows and columns.
if mod(cols, 2)
xrange = [-(cols-1)/2:(cols-1)/2]/(cols-1);
xrange = [-cols/2:(cols/2-1)]/cols;
if mod(rows, 2)
yrange = [-(rows-1)/2:(rows-1)/2]/(rows-1);
yrange = [-rows/2:(rows/2-1)]/rows;
[x, y] = meshgrid(xrange, yrange);
radius = sqrt(x.^2 + y.^2); % A matrix with every pixel = radius relative to centre.
f = ifftshift( 1 ./ (1.0 + (radius ./ cutoff).^(2*n)) ); % The filter