Mercurial > hg > octave-lojdl
changeset 15690:7d21456c09d1
gray2ind: also accept binary images and default n to 2 in such cases
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Mon, 12 Nov 2012 05:25:37 +0000 |
parents | 14b7679891dd |
children | dffb28f47ea8 |
files | scripts/image/gray2ind.m |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/gray2ind.m +++ b/scripts/image/gray2ind.m @@ -20,9 +20,11 @@ ## @deftypefn {Function File} {[@var{img} =} gray2ind (@var{I}) ## @deftypefnx {Function File} {[@var{img} =} gray2ind (@var{I}, @var{n}) ## @deftypefnx {Function File} {[@var{img}, @var{map} =} gray2ind (@dots{}) -## Convert a gray scale intensity image to an Octave indexed image. +## Convert a gray scale or binary image to an indexed image. +## ## The indexed image will consist of @var{n} different intensity values. -## If not given @var{n} defaults to 64. +## If not given @var{n} defaults to 64 and 2 for gray scale and binary images +## respectively. ## @seealso{ind2gray, rgb2ind} ## @end deftypefn @@ -35,6 +37,12 @@ if (nargin < 1 || nargin > 2) print_usage (); endif + + ## default n is different if image is logical + if (nargin < 2 && isa (I, "logical")) + n = 2; + endif + C = class (I); if (! ismatrix (I) || ndims (I) != 2) error ("gray2ind: first input argument must be a gray scale image"); @@ -44,7 +52,7 @@ endif ints = {"uint8", "uint16", "int8", "int16"}; floats = {"double", "single"}; - if (! ismember (C, {ints{:}, floats{:}})) + if (! ismember (C, {ints{:}, floats{:}, "logical"})) error ("gray2ind: invalid data type '%s'", C); endif if (ismember (C, floats) && (min (I(:)) < 0 || max (I(:)) > 1))