function I2= iir(I,f,varargin)
%IIR Increases the resolution of an image by interpolation
% B= IIR(A,f) returns image stored in array A with resolution increased by 
% factor 'f' in both dimensions. 'A' must be an array containing the image 
% data (as returned by IMREAD for instance). It can be grayscale or color.
% Parameter 'f' is NOT a %. To increase to double size use f= 1.
% 
% Additional parameters:
% B= IIR(A,f,'Display','off') eliminates display of both images, the original 
% and the modified. Deafult 'on'
% 
% B= IIR(A,f,'Method',method) Allows to choose between two methods of 
% interpolation: splines or PCHIP (Piecewise Cubic Hermite Interpolating Polynomial). 
% 'method' must be a string character, either 'spline' or 'pchip'. Default
% 'spline'


% Defaults
method= 'spline';
displ= 'on';

% Extract optional arguments
for j= 1:2:length(varargin)
	switch varargin{j}
		case 'Method'
			method= varargin{j+1};
		case 'Display'
			displ= varargin{j+1};
		otherwise
			error('Unknown parameter name. Use ''Display'' or ''Method''');
	end
end

% Check parameter values
if ~strcmp(displ,'on') & ~strcmp(displ,'off')
	error('Unknown DISPLAY value. Use ''on'' or ''off''');
end
if ~strcmp(method,'spline') & ~strcmp(method,'pchip')
	error('Unknown METHOD value. Use ''spline'' or ''pchip''');
end


% ----------------------------
% Sizes and new image array
ncol= ceil(size(I,2)+ size(I,2)*f);
nrow= ceil(size(I,1)+ size(I,1)*f);
I2= uint8(zeros(nrow,ncol,3));

% Loop through rows & cols
	for j= 1:size(I,1)
		for c= 1:size(I,3)
			I2(j,:,c)= expand(double(I(j,:,c)),ncol,method);  
		end
	end
	for j= 1:size(I2,2)
		for c= 1:size(I,3)
			I2(:,j,c)= expand(double(I2(1:size(I,1),j,c)),nrow,method);
		end
	end

% Plot images
if strcmp(displ,'on')
	figure(1)
		image(I);
		axis off
		axis image
	figure(2)
		image(I2);
		axis off
		axis image
end

