changeset 15514:7a0a202fedfe

iscolormap: new function for image
author Carnë Draug <carandraug+dev@gmail.com>
date Fri, 12 Oct 2012 22:38:20 +0200
parents 3ae8c1ee7365
children 8d64e87c00cf
files NEWS doc/interpreter/image.txi scripts/image/iscolormap.m scripts/image/module.mk
diffstat 4 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS
+++ b/NEWS
@@ -93,10 +93,11 @@
       
  ** Other new functions added in 3.8.0:
 
-      betaincinv   erfcinv      polyeig      shrinkfaces 
-      cmpermute    findfigs     splinefit
-      cmunique     fminsearch   tetramesh
-      colorcube    lines        rgbplot     
+      betaincinv   erfcinv      lines      rgbplot
+      cmpermute    findfigs     polyeig    shrinkfaces
+      cmunique     fminsearch   splinefit
+      colorcube    iscolormap   tetramesh
+
  ** Deprecated functions.
 
     The following functions were deprecated in Octave 3.4 and have been
--- a/doc/interpreter/image.txi
+++ b/doc/interpreter/image.txi
@@ -117,6 +117,8 @@
 an RGB color.  The color map must be of class @code{double} with values
 between 0 and 1.
 
+@DOCSTRING(iscolormap)
+
 @DOCSTRING(gray2ind)
 
 @DOCSTRING(ind2gray)
new file mode 100644
--- /dev/null
+++ b/scripts/image/iscolormap.m
@@ -0,0 +1,45 @@
+## Copyright (C) 2012 Carnë Draug
+##
+## This file is part of Octave.
+##
+## Octave 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 3 of the License, or (at
+## your option) any later version.
+##
+## Octave 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 Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} iscolormap (@var{cm})
+## Return true if @var{cm} is a colormap.
+##
+## A colormap is an @var{n} row by 3 column matrix.  The columns contain red,
+## green, and blue intensities respectively.  All entries should be between 0
+## and 1 inclusive.
+##
+## @seealso{colormap, rgbplot}
+## @end deftypefn
+
+## Author: Carnë Draug <carandraug+dev@gmail.com>
+
+function retval = iscolormap (cm)
+
+  if (nargin != 1)
+    print_usage;
+  endif
+
+  retval = (ismatrix (cm) && isreal (cm) && isnumeric (cm) &&
+            columns(cm) == 3 && ndims (cm) == 2 && isa (cm, "double") &&
+            min (cm(:)) >= 0 && max (cm(:)) <= 1);
+
+endfunction
+
+%!assert (iscolormap (jet (64)))
+%!assert (iscolormap (magic (4)), false)
--- a/scripts/image/module.mk
+++ b/scripts/image/module.mk
@@ -18,6 +18,7 @@
   image/hot.m \
   image/hsv.m \
   image/hsv2rgb.m \
+  image/iscolormap.m \
   image/image.m \
   image/imagesc.m \
   image/imfinfo.m \