Commits

carandraug  committed 74ff287

Remove default colormap for ind2rgb and ind2gray.

  • Participants
  • Parent commits e88b31c

Comments (0)

Files changed (4)

     doubles.  For certain operations, such as fft2, the image must still be
     converted to double in order to work.
 
+    Other changes include fixes to the way indexed images are read from a
+    colormap depending on the image class (integer images have a -1 offset to
+    the colormap row number).
+
  ** The datevec function has been extended for better Matlab compatibility.
     It now accepts string inputs in the following numerical formats: 12, 21,
     22, 26, 29, 31.  This is undocumented, but verifiable, Matlab behavior.

File scripts/image/ind2gray.m

 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{I} =} ind2gray (@var{x})
-## @deftypefnx {Function File} {@var{I} =} ind2gray (@var{x}, @var{map})
+## @deftypefn {Function File} {@var{I} =} ind2gray (@var{x}, @var{map})
 ## Convert a color indexed image to a grayscale intensity image.
 ##
-## If @var{map} is omitted, the current colormap is used to determine the
-## intensities.  If it doesn't contain enough colors, it is padded it with the
-## last color in the map.
+## The image @var{x} must be an indexed image which will be converted using the
+## colormap @var{cmap}.  If @var{cmap} does not contain enough colors for the
+## image, pixels in @var{x} outside the range are mapped to the last color in
+## the map before conversion to grayscale.
 ##
 ## The output @var{I} is of the same class as the input @var{x} and may be
 ## one of @code{uint8}, @code{uint16}, @code{single}, or @code{double}.
 ## Created: July 1994
 ## Adapted-By: jwe
 
-function I = ind2gray (x, map = colormap ())
+function I = ind2gray (x, map)
 
-  if (nargin < 1 || nargin > 2)
+  if (nargin != 2)
     print_usage ();
   endif
   [x, map] = ind2x ("ind2rgb", x, map);
   ## Convert colormap to same class as that of input so that when reshape
   ## later, produces output of the same type as the input
   cls = class (x);
-  if (isinteger (x)) 
+  if (isinteger (x))
+    ## if we later add support for int16 images, this will not work. Look into
+    ## im2int16 from image package for such case
     map *= intmax (cls);
   elseif (strcmp (cls, "single"))
     map = single (map);

File scripts/image/ind2rgb.m

 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{rgb} =} ind2rgb (@var{x})
-## @deftypefnx {Function File} {@var{rgb} =} ind2rgb (@var{x}, @var{map})
+## @deftypefn  {Function File} {@var{rgb} =} ind2rgb (@var{x}, @var{map})
 ## @deftypefnx {Function File} {[@var{R}, @var{G}, @var{B}] =} ind2rgb (@dots{})
 ## Convert an indexed image to red, green, and blue color components.
-## If @var{map} is omitted, the current colormap is used for the conversion.
-## When the colormap does not contain enough colors it is padded to the
-## required length using the last color in the map.
 ##
-## The output may be a single MxNx3 matrix where M is the number of rows in
-## @var{x} and N is the number of columns in @var{x}.  Alternatively,
-## individual red, green, and blue color matrices of size MxN may be
-## returned.
+## The image @var{x} must be an indexed image which will be converted using the
+## colormap @var{cmap}.  If @var{cmap} does not contain enough colors for the
+## image, pixels in @var{x} outside the range are mapped to the last color in
+## the map.
+##
+## The output may be a single RGB image (MxNx3 matrix where M and N are the
+## original image @var{x} dimensions, one for each of the red, green and blue
+## channels).  Alternatively, the individual red, green, and blue color matrices
+## of size MxN may be returned.
+##
 ## @seealso{rgb2ind, ind2gray, hsv2rgb, ntsc2rgb}
 ## @end deftypefn
 
 ## Created: July 1994
 ## Adapted-By: jwe
 
-function [R, G, B] = ind2rgb (x, map = colormap ())
+function [R, G, B] = ind2rgb (x, map)
 
-  if (nargin < 1 || nargin > 2)
+  if (nargin != 2)
     print_usage ();
   endif
   [x, map] = ind2x ("ind2rgb", x, map);

File scripts/image/private/ind2x.m

 
   rm = rows (map);
   if (rm < maxidx)
-    ## Pad with the last color in the map.
+    ## Pad with the last color in the map for matlab compatibility
     pad = repmat (map(end,:), maxidx-rm, 1);
     map(end+1:maxidx, :) = pad;
   endif