# image_resize

## PURPOSE

image_resize - resize an image using bicubic interpolation

## SYNOPSIS

function newimg = image_resize(img,p1,q1,r1)

## DESCRIPTION

     image_resize - resize an image using bicubic interpolation

       newimg = image_resize(img,nx,ny,nz);
     or
       newimg = image_resize(img,newsize);

       Works for 2D, 2D 2 or 3 channels, 3D images.

       Copyright (c) 2004 Gabriel Peyr

## CROSS-REFERENCE INFORMATION

This function calls:

- image_resize image_resize - resize an image using bicubic interpolation

This function is called by:

- image_resize image_resize - resize an image using bicubic interpolation

## SOURCE CODE

    0001 function newimg = image_resize(img,p1,q1,r1)
    0002
    0003 % image_resize - resize an image using bicubic interpolation
    0004 %
    0005 %   newimg = image_resize(img,nx,ny,nz);
    0006 % or
    0007 %   newimg = image_resize(img,newsize);
    0008 %
    0009 %   Works for 2D, 2D 2 or 3 channels, 3D images.
    0010 %
    0011 %   Copyright (c) 2004 Gabriel Peyr
    0012
    0013 if nargin==2
    0014     % size specified as an array
    0015     q1 = p1(2);
    0016     if length(p1)>2
    0017         r1 = p1(3);
    0018     else
    0019         r1 = size(img,3);
    0020     end
    0021     p1 = p1(1);
    0022 end
    0023
    0024 if nargin<4
    0025     r1 = size(img,3);
    0026 end
    0027
    0028 if ndims(img)<2 || ndims(img)>3
    0029     error('Works only for grayscale or color images');
    0030 end
    0031
    0032 if ndims(img)==3 && size(img,3)<4
    0033     % RVB image
    0034     newimg = zeros(p1,q1, size(img,3));
    0035     for m=1:size(img,3)
    0036         newimg(:,:,m) = image_resize(img(:,:,m), p1, q1);
    0037     end
    0038     return;
    0039 elseif ndims(img)==3
    0040     p = size(img,1);
    0041     q = size(img,2);
    0042     r = size(img,3);
    0043     [Y,X,Z] = meshgrid( (0:q-1)/(q-1), (0:p-1)/(p-1), (0:r-1)/(r-1)  );
    0044     [YI,XI,ZI] = meshgrid( (0:q1-1)/(q1-1), (0:p1-1)/(p1-1), (0:r1-1)/(r1-1) );
    0045     newimg = interp3( Y,X,Z, img, YI,XI,ZI ,'nearest');
    0046     return;
    0047 end
    0048
    0049 p = size(img,1);
    0050 q = size(img,2);
    0051 [Y,X] = meshgrid( (0:q-1)/(q-1), (0:p-1)/(p-1) );
    0052 [YI,XI] = meshgrid( (0:q1-1)/(q1-1), (0:p1-1)/(p1-1) );
    0053 newimg = interp2( Y,X, img, YI,XI,'nearest');