X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fimresize.m;fp=octave_packages%2Fimage-1.0.15%2Fimresize.m;h=84d40d959512e73fcd4bf0a2ea8e8b428589b42d;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/image-1.0.15/imresize.m b/octave_packages/image-1.0.15/imresize.m new file mode 100644 index 0000000..84d40d9 --- /dev/null +++ b/octave_packages/image-1.0.15/imresize.m @@ -0,0 +1,67 @@ +## Copyright (C) 2005 Søren Hauberg +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} @var{B}= imresize (@var{A}, @var{m}) +## Scales the image @var{A} by a factor @var{m} using bicubic neighbour +## interpolation. If @var{m} is less than 1 the image size will be reduced, +## and if @var{m} is greater than 1 the image will be enlarged. +## +## @deftypefnx {Function File} @var{B}= imresize (@var{A}, @var{m}, @var{interp}) +## Same as above except @var{interp} interpolation is performed instead of +## using nearest neighbour. @var{interp} can be any interpolation method supported by interp2. +## By default, bicubic interpolation is used. +## +## @deftypefnx {Function File} @var{B}= imresize (@var{A}, [@var{mrow} @var{mcol}]) +## Scales the image @var{A} to be of size @var{mrow}x@var{mcol}. +## +## @deftypefnx {Function File} @var{B}= imresize (@var{A}, [@var{mrow} @var{mcol}], @var{interp}) +## Same as above except @var{interp} interpolation is performed. @var{interp} can +## be any interpolation method supported by interp2. +## @seealso{imremap, imrotate, interp2} +## @end deftypefn + +function ret = imresize(im, m, interp = "bicubic") + if (nargin < 2) + error ("imresize: not enough input arguments"); + endif + + [row, col, num_planes, tmp] = size (im); + if (tmp != 1 || (num_planes != 1 && num_planes != 3)) + error ("imresize: the first argument has must be an image"); + endif + + ## Handle the argument that describes the size of the result + if (length (m) == 1) + new_row = round (row*m); + new_col = round (col*m); + elseif (length (m) == 2) + new_row = m (1); + new_col = m (2); + m = min (new_row/row, new_col/col); + else + error ("imresize: second argument mest be a scalar or a 2-vector"); + end + + ## Handle the method argument + if (!any (strcmpi (interp, {"nearest", "linear", "bilinear", "cubic", "bicubic", "pchip"}))) + error ("imresize: unsupported interpolation method"); + endif + + + ## Perform the actual resizing + [XI, YI] = meshgrid (linspace (1,col, new_col), linspace (1, row, new_row) ); + ret = imremap (im, XI, YI, interp); +endfunction