OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimBandLutFilter.h
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: MIT
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Oscar Kramer
9 //
10 //*************************************************************************
11 // $Id: ossimBandLutFilter.h 23616 2015-11-11 19:50:29Z dburken $
12 #ifndef ossimBandLutFilter_HEADER
13 #define ossimBandLutFilter_HEADER
14 
18 #include <vector>
19 
20 class ossimImageData;
21 
22 /***************************************************************************************************
23  *
24  * This class provides a look-up-table remap capability for performing band-separate remapping to
25  * an output with the same number of bands. This is similar to ossimIndexToRgbLutFilter except it
26  * works independently on the input bands. The number of output bands is necessarily equal to the
27  * number of input bands, but the scalar data type between input and output can be different (just
28  * like with the ossimScalarRemapper).
29  *
30  * The LUT is provided as a KWL with several remapping modes supported:
31  *
32  * Literal: Only those indices represented in the KWL are remapped to the values indicated. All
33  * other pixel values are mapped to the NULL pixel (0,0,0). Note that this is only meaningful for
34  * integer input scalar types since a normalized input will likely not find an exact match.
35  *
36  * Arbitrary piecewise linear ("vertices"): The LUT KWL provides vertices to contiguous line
37  * segments. Pixel values falling between specified indices are linearly interpolated between
38  * adjacent vertices. Any index pixel values falling outside the range between min and max vertex
39  * indices will be mapped to the NULL pixel.
40  *
41  * Regular piecewise linear ("regular"): The entries in the KWL do not correspond to any specific
42  * index (except the first and the last entries that correspond to the min and max pixel values).
43  * Remaining intermediate entries are equally spaced in index space so that the line segments are of
44  * equal length. The min and max values are queried from the input source, but can be overriden with
45  * the "min_value" and "max_value" keywords in the LUT KWL.
46  *
47  * Here are example KWLs for the three modes, Note that the band identifier is optional if the input
48  * image is single band, or if the same LUT is to be applied to all bands.
49  *
50  * If the input is multi-band, the same mode applies to all bands. The band numbers are 0-based.
51  * If band-specific entries are being provided (i.e., the "band" prefix is being used) then at least
52  * one entry for each band must be provided, otherwise remaining bands will be ignored.
53  *
54  * First for the "literal" remap:
55  *
56  * type: ossimBandLutFilter
57  * mode: literal
58  * [band0.]entry0.in: 0
59  * [band0.]entry0.out: 1
60  * [band0.]entry1.in: 128
61  * [band0.]entry1.out: 2
62  * [band0.]entry2.in: 255
63  * [band0.]entry2.out: 3
64  *
65  * The above KWL will map only pixels with input values of 0, 128, and 255. All other indices will
66  * map to the null value. This mode is not appropriate for floating-point input scalar types.
67  * However, no checks are made so pay attention to what you put in your LUT!
68  *
69  * Example for arbitrary piecewise linear, a.k.a. "interpolated" mode:
70  *
71  * type: ossimBandLutFilter
72  * mode: interpolated
73  * [band0.]entry0.in: 0.1
74  * [band0.]entry0.out: 255
75  * [band0.]entry1.in: 0.5
76  * [band0.]entry1.out: 128
77  * [band0.]entry2.in: 0.90
78  * [band0.]entry2.out: 1
79  *
80  * The above KWL is a sort of heat map where input values between 0 and 0.5 will linearly map to
81  * discrete numbers 255 to 128. Then values between 0.5 to 1.0 will linearly map to
82  * values 128 down to 0. Effectively this inverts the colors and performs a scalar remap to UInt8.
83  * Note that any input values below 0.1 ad above 0.9 are outside of the remap range and will map to
84  * the null pixel. This mode is appropriate for both integer and floating-point inputs.
85  *
86  * The table can be contained in a separate file from the main KWL state file. In this case, the
87  * loadState can accept a file name in place of a complete table:
88  *
89  * type: ossimBandLutFilter
90  * lut_file: <path to LUT KWL file>
91  *
92  * The format of the LUT KWL file is just as specified above for the inline case.
93  *
94  * If you want an output scalar type different from the input scalar type, you will need to indicate
95  * that either programmatically or via the keyword (specified in the state KWL or LUT KWL file:
96  *
97  * scalar_type: <ossimScalarType> (see ossimScalarTypeLut for list of enumerated strings)
98  *
99  **************************************************************************************************/
101 {
102 public:
103  enum Mode { UNKNOWN=0, LITERAL = 1, INTERPOLATED = 2 };
104 
106 
107  virtual ossimRefPtr<ossimImageData> getTile(const ossimIrect& origin,
108  ossim_uint32 resLevel=0);
109 
110  void setMode(Mode mode) { theMode = mode; }
111  Mode getMode() const { return theMode; }
112 
113  virtual ossimScalarType getOutputScalarType() const { return theOutputScalarType; }
114 
118  virtual void setOutputScalarType(ossimScalarType scalarType);
119  virtual void setOutputScalarType(ossimString scalarType);
120 
125  void setLut(const ossimFilename& file);
126 
127  virtual void initialize();
128 
129  virtual bool saveState(ossimKeywordlist& kwl, const char* prefix=NULL)const;
130 
131  virtual bool loadState(const ossimKeywordlist& kwl, const char* prefix=NULL);
132 
133 protected:
134  virtual ~ossimBandLutFilter();
135 
139  void allocate();
140  bool initializeLut(const ossimKeywordlist& kwl, const char* prefix=0);
141 
142  std::vector< std::map<double, double> > theLut;
143 
148 
149 TYPE_DATA
150 };
151 
152 #endif /* #ifndef ossimBandLutFilter_HEADER */
Represents serializable keyword/value map.
ossimScalarType theOutputScalarType
#define TYPE_DATA
Definition: ossimRtti.h:339
unsigned int ossim_uint32
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossimRefPtr< ossimImageData > theTile
ossimScalarType
ossimFilename theLutFile
std::vector< std::map< double, double > > theLut
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
#define OSSIM_DLL
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
void setMode(Mode mode)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)