From: <car...@us...> - 2012-09-02 02:37:18
|
Revision: 10943 http://octave.svn.sourceforge.net/octave/?rev=10943&view=rev Author: carandraug Date: 2012-09-02 02:37:12 +0000 (Sun, 02 Sep 2012) Log Message: ----------- isgray: use shared private functions for checks and added test blocks Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m trunk/octave-forge/main/image/inst/isgray.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:33:14 UTC (rev 10942) +++ trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:37:12 UTC (rev 10943) @@ -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 Modified: trunk/octave-forge/main/image/inst/isgray.m =================================================================== --- trunk/octave-forge/main/image/inst/isgray.m 2012-09-02 02:33:14 UTC (rev 10942) +++ trunk/octave-forge/main/image/inst/isgray.m 2012-09-02 02:37:12 UTC (rev 10943) @@ -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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |