changeset 579:cad86b82d447

is_double_image: new private function to check if an image of class double is valid
author carandraug
date Sun, 02 Sep 2012 03:41:40 +0000
parents 96b49bbc07cd
children cc447688e3f6
files inst/isgray.m inst/isrgb.m inst/private/is_double_image.m
diffstat 3 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/inst/isgray.m
+++ b/inst/isgray.m
@@ -43,7 +43,7 @@
   elseif (ndims (img) == 2)
     switch (class (img))
       case "double"
-        bool = ispart (@is_gray_double, img);
+        bool = ispart (@is_double_image, img);
       case {"uint8", "uint16"}
         bool = true;
     endswitch
@@ -51,10 +51,6 @@
 
 endfunction
 
-function bool = is_gray_double (img)
-  bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:)));
-endfunction
-
 %!shared a
 %! a = rand (100);
 %!assert (isgray (a), true);
--- a/inst/isrgb.m
+++ b/inst/isrgb.m
@@ -44,7 +44,7 @@
   elseif (ndims (img) == 3 && size (img, 3) == 3)
     switch (class (img))
       case "double"
-        bool = ispart (@is_rgb_double, img);
+        bool = ispart (@is_double_image, img);
       case {"uint8", "uint16"}
         bool = true;
     endswitch
@@ -52,10 +52,6 @@
 
 endfunction
 
-function bool = is_rgb_double (img)
-  bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:)));
-endfunction
-
 %!# Non-matrix
 %!assert(isrgb("this is not a RGB image"),false);
 
new file mode 100644
--- /dev/null
+++ b/inst/private/is_double_image.m
@@ -0,0 +1,21 @@
+## Copyright (C) 2012 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 3 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 <http://www.gnu.org/licenses/>.
+
+## simple check used by some functions. Images of the double class must have
+## all their values between 0 and 1 or be NaN
+
+function bool = is_double_image (img)
+  bool = all ((img(:) >= 0 & img(:) <= 1) | isnan (img(:)));
+endfunction