Mercurial > hg > octave-lyh
changeset 15712:74ff287f41cb
Remove default colormap for ind2rgb and ind2gray.
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Sun, 02 Dec 2012 13:12:53 +0100 |
parents | e88b31c485c0 |
children | 168e380c8f18 |
files | NEWS scripts/image/ind2gray.m scripts/image/ind2rgb.m scripts/image/private/ind2x.m |
diffstat | 4 files changed, 28 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -96,6 +96,10 @@ 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.
--- a/scripts/image/ind2gray.m +++ b/scripts/image/ind2gray.m @@ -17,13 +17,13 @@ ## <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}. @@ -40,9 +40,9 @@ ## 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); @@ -53,7 +53,9 @@ ## 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);
--- a/scripts/image/ind2rgb.m +++ b/scripts/image/ind2rgb.m @@ -17,18 +17,20 @@ ## <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 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 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 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 @@ -36,9 +38,9 @@ ## 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);
--- a/scripts/image/private/ind2x.m +++ b/scripts/image/private/ind2x.m @@ -48,7 +48,7 @@ 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