Mercurial > hg > octave-image
changeset 494:fdfaaf68dab0
mat2gray: fixes on input checking
author | carandraug |
---|---|
date | Thu, 10 Nov 2011 03:10:43 +0000 |
parents | 69d416f9d4a0 |
children | 21a408d3da04 |
files | inst/mat2gray.m |
diffstat | 1 files changed, 13 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/mat2gray.m +++ b/inst/mat2gray.m @@ -1,8 +1,9 @@ -## Copyright (C) 1999,2000 Kai Habel +## Copyright (C) 1999,2000 Kai Habel <kai.habel@gmx.de> +## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com> ## ## 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 +## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, @@ -16,29 +17,26 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{I}= mat2gray (@var{M},[min max]) ## Converts a matrix to a intensity image. +## @seealso{gray2ind, ind2gray, rgb2gray} ## @end deftypefn -## Author: Kai Habel <kai.habel@gmx.de> -## Date: 22/03/2000 - function I = mat2gray (M, scale) - if (nargin < 1|| nargin > 2) - usage ("mat2gray(...) number of arguments must be 1 or 2"); + if (nargin < 1 || nargin > 2) + print_usage; + elseif (!ismatrix (M)) + error ("mat2gray(M,...) M must be a matrix"); + elseif (nargin == 2 && (!isvector (scale) || numel (scale) != 2)) + error ("mat2gray(M,scale) scale must be a vector with 2 elements"); endif - if (!ismatrix (M)) - usage ("mat2gray(M,...) M must be a matrix"); - endif - + ## what if the matrix has more than 2D? if (nargin == 1) Mmin = min (min (M)); Mmax = max (max (M)); else - if (isvector (scale)) - Mmin = min (scale (1), scale (2)); - Mmax = max (scale (1), scale (2)); - endif + Mmin = min (scale (1), scale (2)); + Mmax = max (scale (1), scale (2)); endif I = (M < Mmin) .* 0;