1 ## Copyright (C) 2005 Søren Hauberg
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} @var{B}= imresize (@var{A}, @var{m})
18 ## Scales the image @var{A} by a factor @var{m} using bicubic neighbour
19 ## interpolation. If @var{m} is less than 1 the image size will be reduced,
20 ## and if @var{m} is greater than 1 the image will be enlarged.
22 ## @deftypefnx {Function File} @var{B}= imresize (@var{A}, @var{m}, @var{interp})
23 ## Same as above except @var{interp} interpolation is performed instead of
24 ## using nearest neighbour. @var{interp} can be any interpolation method supported by interp2.
25 ## By default, bicubic interpolation is used.
27 ## @deftypefnx {Function File} @var{B}= imresize (@var{A}, [@var{mrow} @var{mcol}])
28 ## Scales the image @var{A} to be of size @var{mrow}x@var{mcol}.
30 ## @deftypefnx {Function File} @var{B}= imresize (@var{A}, [@var{mrow} @var{mcol}], @var{interp})
31 ## Same as above except @var{interp} interpolation is performed. @var{interp} can
32 ## be any interpolation method supported by interp2.
33 ## @seealso{imremap, imrotate, interp2}
36 function ret = imresize(im, m, interp = "bicubic")
38 error ("imresize: not enough input arguments");
41 [row, col, num_planes, tmp] = size (im);
42 if (tmp != 1 || (num_planes != 1 && num_planes != 3))
43 error ("imresize: the first argument has must be an image");
46 ## Handle the argument that describes the size of the result
48 new_row = round (row*m);
49 new_col = round (col*m);
50 elseif (length (m) == 2)
53 m = min (new_row/row, new_col/col);
55 error ("imresize: second argument mest be a scalar or a 2-vector");
58 ## Handle the method argument
59 if (!any (strcmpi (interp, {"nearest", "linear", "bilinear", "cubic", "bicubic", "pchip"})))
60 error ("imresize: unsupported interpolation method");
64 ## Perform the actual resizing
65 [XI, YI] = meshgrid (linspace (1,col, new_col), linspace (1, row, new_row) );
66 ret = imremap (im, XI, YI, interp);