Mercurial > hg > octave-image
changeset 817:201fd05fbc79
intlut: fix for images of signed integers and with intmax() values.
* intlut.m: convert image/indices to class double and add 1 in case it
has any value equal to its class intmax(). Also add an extra 32768 if the
class is int16 to have an offset based on zero. Fix and add tests for
these cases.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 29 Oct 2013 21:42:24 +0000 |
parents | 7779d96939c2 |
children | 355bd9c476d9 |
files | inst/intlut.m |
diffstat | 1 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/intlut.m +++ b/inst/intlut.m @@ -19,7 +19,7 @@ ## ## Replaces the values from the matrix @var{A} with the corresponding value ## from the look up table @var{LUT} (this is the grayscale equivalent to an -## indexed image). IT is equivalent to @code{@var{LUT}(@var{A} +1)}. +## indexed image). ## ## @var{A} and @var{LUT} must be of the same class, and uint8, uint16, or int16. ## @var{LUT} must have exactly 256 elements for class uint8, and 65536 for @@ -48,7 +48,16 @@ error ("intlut: LUT must have %d elements for class %s", max_numel, cl); endif - B = LUT(A+1); + ## We need to convert to double in case of the values in A is + ## equal to intmax (class (A)) + A = double (A); + if (strcmp ("int16", cl)) + A += 32769; + else + A += 1; + endif + + B = LUT(A); endfunction %!demo @@ -57,7 +66,11 @@ %!assert (intlut (uint8 (1:4), uint8 ( 255:-1:0)), uint8 (254:-1:251)); %!assert (intlut (uint16 (1:4), uint16 (65535:-1:0)), uint16 (65534:-1:65531)); -%!assert (intlut (int16 (1:4), int16 (32767:-1:-32768)), int16 (32766:-1:32763)); +%!assert (intlut (int16 (1:4), int16 (32767:-1:-32768)), int16 (-2:-1:-5)); + +%!assert (intlut (uint8 (255), uint8 (0:255)), uint8 (255)); +%!assert (intlut (uint16 (65535), uint16 (0:65535)), uint16 (65535)); +%!assert (intlut (int16 (32767), int16 (-32768:32767)), int16 (32767)); %!error intlut () %!error intlut ("text")