]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/uintlut.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / uintlut.m
1 ## Copyright (C) 2004 Josep Mones i Teixidor
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{B} = } uintlut (@var{A},@var{LUT})
18 ## Computes matrix B by using A as an index to lookup table LUT.
19 ##
20 ## B = uintlut(A, LUT) calculates a matrix B by using @var{LUT} as a
21 ## lookup table indexed by values in @var{A}.
22 ## 
23 ## B class is the same as @var{LUT}. 
24 ## @end deftypefn
25
26 ## Author:  Josep Mones i Teixidor <jmones@puntbarra.com>
27
28 function B = uintlut(A, LUT)
29   if (nargin != 2)
30     usage("B = uintlut(A, LUT)");
31   endif
32
33   ## We convert indexing array A to double since even CVS version of
34   ## Octave is unable to use non-double arrays as indexing types. This
35   ## won't be needed in the future eventually.
36   B=LUT(double(A));
37 endfunction
38
39 %!demo
40 %! uintlut(uint8([1,2,3,4]),uint8([255:-1:0]));
41 %! % Returns a uint8 array [255,254,253,252]
42
43 %!assert(uintlut(uint8([1,2,3,4]),uint8([255:-1:0])), uint8([255:-1:252]));
44 %!assert(uintlut(uint16([1,2,3,4]),uint16([255:-1:0])), uint16([255:-1:252]));
45 %!assert(uintlut(uint32([1,2,3,4]),uint32([255:-1:0])), uint32([255:-1:252]));
46 %!assert(uintlut(uint64([1,2,3,4]),uint64([255:-1:0])), uint64([255:-1:252]));
47
48 %
49 % $Log$
50 % Revision 1.2  2007/03/23 16:14:38  adb014
51 % Update the FSF address
52 %
53 % Revision 1.1  2006/08/20 12:59:36  hauberg
54 % Changed the structure to match the package system
55 %
56 % Revision 1.2  2004/08/11 15:04:59  pkienzle
57 % Convert dos line endings to unix line endings
58 %
59 % Revision 1.1  2004/08/08 21:20:25  jmones
60 % uintlut and padarray functions added
61 %
62 %