Mercurial > forge
changeset 10757:902a9fdaf948 octave-forge
isgray: use shared private functions for checks and added test blocks
author | carandraug |
---|---|
date | Sun, 02 Sep 2012 02:37:12 +0000 |
parents | 42c5130baae2 |
children | 23508ebccaa3 |
files | main/image/inst/isbw.m main/image/inst/isgray.m |
diffstat | 2 files changed, 15 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/main/image/inst/isbw.m Sun Sep 02 02:33:14 2012 +0000 +++ b/main/image/inst/isbw.m Sun Sep 02 02:37:12 2012 +0000 @@ -62,7 +62,7 @@ endfunction function bool = is_bw_nonlogical (BW) - bool = all ((BW == 1)(:) + (BW == 0)(:)); + bool = all ((BW(:) == 1) + (BW(:) == 0)); endfunction %!shared a
--- a/main/image/inst/isgray.m Sun Sep 02 02:33:14 2012 +0000 +++ b/main/image/inst/isgray.m Sun Sep 02 02:37:12 2012 +0000 @@ -38,15 +38,12 @@ endif bool = false; - if (ismatrix (img) && ndims (img) == 2 && !issparse (img) && !isempty (img)) + if (!isimage (img)) + bool = false; + elseif (ndims (img) == 2) switch (class (img)) case "double" - ## to speed this up, we can look at a sample of the image first - bool = is_gray_double (img(1:ceil (rows (img) /100), 1:ceil (columns (img) /100))); - if (bool) - ## sample was true, we better make sure it's real - bool = is_gray_double (img); - endif + bool = ispart (@is_gray_double, img); case {"uint8", "uint16"} bool = true; endswitch @@ -57,3 +54,13 @@ 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(50, 50) = 2; +%!assert (isgray (a), false); +%! a = uint8 (randi (255, 100)); +%!assert (isgray (a), true); +%! a = int8 (a); +%!assert (isgray (a), false);