diff -r afbef2f579c9 scripts/image/private/colorspace_conversion_input_check.m --- a/scripts/image/private/colorspace_conversion_input_check.m Tue Jan 16 21:23:51 2018 -0800 +++ b/scripts/image/private/colorspace_conversion_input_check.m Wed Jan 17 17:30:41 2018 +0000 @@ -47,8 +47,9 @@ function [in_arg, sz, is_im, is_nd] ... ## Allow for ND images, i.e., multiple images on the 4th dimension. nd = ndims (in_arg); - if (nd == 3) + if (nd < 4) is_nd = false; + sz(end+1:4) = 1; elseif (nd == 4) is_nd = true; in_arg = permute (in_arg, [1 2 4 3]); diff -r afbef2f579c9 scripts/image/rgb2gray.m --- a/scripts/image/rgb2gray.m Tue Jan 16 21:23:51 2018 -0800 +++ b/scripts/image/rgb2gray.m Wed Jan 17 17:30:41 2018 +0000 @@ -59,14 +59,8 @@ function I = rgb2gray (rgb) ## Matlab always returning class double, is a Matlab bug (see patch #8709) I = rgb * xform; - ## Restore size if necessary - if (is_im) - if (is_nd) - I = reshape (I, [sz(1), sz(2), sz(4)]); - else - I = reshape (I, sz(1:2)); - endif - endif + sz(3) = 1; # grayscale images have 3rd dimension of length 1 + I = colorspace_conversion_revert (I, sz, is_im, is_nd); endfunction @@ -82,9 +76,9 @@ endfunction ## Test ND input %!test %! rgb = rand (16, 16, 3, 5); -%! I = zeros (16, 16, 5); +%! I = zeros (16, 16, 1, 5); %! for i = 1:5 -%! I(:,:,i) = rgb2gray (rgb(:,:,:,i)); +%! I(:,:,1,i) = rgb2gray (rgb(:,:,:,i)); %! endfor %! assert (rgb2gray (rgb), I);