Loading...
Searching...
No Matches
PaletteRaster.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5TerraLib is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 3 of the License,
8or (at your option) any later version.
9
10TerraLib is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License
16along with TerraLib. See COPYING. If not, write to
17TerraLib Team at <terralib-team@terralib.org>.
18*/
19
20/*!
21\file terralib/rp/PaletteRaster.h
22
23\brief Raster functions to generate palette image.
24*/
25
26#ifndef __TERRALIB_RP_INTERNAL_PALETTERASTER_H
27#define __TERRALIB_RP_INTERNAL_PALETTERASTER_H
28
29
30
31// TerraLib
32#include "Config.h"
33#include "../raster/Band.h"
34#include "../raster/Grid.h"
35#include "../raster/Raster.h"
36#include "../maptools/RasterTransform.h"
37
38//stl
39#include <list>
40
41namespace te
42{
43 namespace rp
44 {
45
46#define NCUBESDIM 32 //!< Number of cubes in a dimension
47#define CUBESIZE 8 //!< CUBESIZE = 256 / NCUBESDIM
48
49 //! \class CubeColor
50 //! \brief Defines a cubic volume in the RGB color space
51 //!
52 //! The class CubeColor defines a cube of size CUBESIZE (=8) centered
53 //! in a given point in RGB color space. It allows the insertion of
54 //! RGB triplets, calculation of the mean color value (per color)
55 //! of triplets inserted and keeping control of population of
56 //! inserted colors as well.
57 //! from Spring code
59 {
60 public:
61
62 /*!
63 \brief CubeColor constructor
64 \param ir: Red component of color cube center
65 \param ig: Green component of color cube center
66 \param ib: Blue component of color cube center
67 */
68 CubeColor(int ir, int ig, int ib);
69
70 /*!
71 \brief Destructor
72 */
74
75 /*!
76 \brief Inserts a triple rgb in CubeColor.
77 \param r: red component of color
78 \param g: green component of color
79 \param b: blue component of color
80 */
81 void InsertTripleRGB(int r, int g, int b);
82
83 /*!
84 \brief Get red component of cube center
85 \return Index of color red
86 */
87 int IndexR() { return m_ibr; }
88
89 /*!
90 \brief Get green component of cube center
91 \return Index of color green
92 */
93 int IndexG() { return m_ibg; }
94
95 /*!
96 \brief Get blue component of cube center
97 \return Index of color blue
98 */
99 int IndexB() { return m_ibb; }
100
101 /*!
102 \brief Get i-th mean color component value.
103 \param i: color component ( 0 = red, 1 = green, 2 = blue )
104 \return i-th mean color component value
105 */
106 double Mean(int i) { return (i < 3 && i >= 0) ? (m_mean[i]) : (0); }
107
108 /*!
109 \brief Get number of Image rgb triples in the CubeColor
110 \return the population of CubeColor
111 */
112 double Pop() { return m_pop; }
113
114 /*!
115 \brief Get the index of GroupColor associated with CubeColor
116 \return the index of CubeColor in the GroupColor.
117 */
118 int GroupColorIndex() { return m_igc; }
119
120 /*!
121 \brief Sets group color index
122 */
123 void SetGroupColorIndex(int index) { m_igc = index; }
124
125 protected:
126 int m_ibr, //!< Index of color red in the color cube space
127 m_ibg, //!< Index of color green in the color cube space
128 m_ibb; //!< Index of color blue in the color cube space
129 int m_igc; //!< Index of GroupColor associated with CubeColor
130 double m_mean[3]; //!< Mean of triples from an Image rgb belonging to this CubeColor
131 double m_pop; //!< Number of Image rgb triples in the CubeColor
132
133 };
134
135 //! \class GroupColor
136 //! \brief Defines a classification context
137 //!
138 //! The class GroupColor is a container of CubeColor objects allowing
139 //! the generation of statistics ( mean value and standard deviation )
140 //! of the colors in the group.
141 //! from Spring code
143 {
144 public:
145
146 /*!
147 \brief Constructor
148 \param ident: group color identifier
149 */
150 GroupColor(int ident);
151
152 /*!
153 \brief Destructor
154 */
156
157 /*!
158 \brief Inserts a CubeColor in the List.
159 \param cc: a CubeColor object
160 */
162
163 /*!
164 \brief Removes the current item from the list.
165 */
167
168 /*!
169 \brief Returns the number of CubeColors in this GroupColor
170 \return TRUE: successs or FALSE: failure
171 */
172 size_t GetNCubeColors() { return m_CClist.size(); }
173
174 /*!
175 \brief Splits the GroupColor in two ones. The new GroupColor will have
176 its id given by newgcid. The list of ColorCubes in the
177 original GroupColor will be divided with the new GroupColor.
178 \param newgcid: new group color identifier
179 \return pointer to CubeColor (NULL if empty)
180 */
181 GroupColor* Split(int newgcid);
182
183 /*!
184 \brief Return Mean[i] of GroupColor
185 \param i: color component ( 0 = red, 1 = green, 2 = blue )
186 */
187 double Mean(int i) { return (i < 3 && i >= 0 && m_pop != 0) ? ((double)m_Ex[i] / m_pop) : ((double)0); }
188
189 /*!
190 \brief Returns the biggest variance
191 */
192 double MaxVar() { return m_varmax; }
193
194 private:
195 int m_id; //!< Id of GroupColor
196 double m_Ex[3]; //!< Expectation of means of CubeColors belonging to this GroupColor
197 double m_Ex2[3]; //!< Expectation of squared means of CubeColors belonging to this GroupColor
198 double m_var[3]; //!< Variance in each dimension of CubeColors belonging to this GroupColor
199 double m_varmax; //!< Biggest variance
200 double m_pop; //!< population of group color
201 std::list<CubeColor*> m_CClist; //!< List of pointers to CubeColors
202 std::list<CubeColor*>::iterator m_itCC; //!< iterator to CubeColors list
203
204 };
205
206 //! \class Codifima
207 //!
208 //! \brief Defines a Codifima class
209 //!
210 //! The class Codifima
211 //! describing the images in use (attribute images, classified images,
212 //! segmented images) and training data set as well.
213 //! from Spring code
214
216 {
217 protected:
218
226 bool k_means();
227 void Clear();
228
229 public:
230 /*!
231 \brief Codifies a rgb raster to a paletta raster
232 \param inputRaster input rgb raster
233 \param rasterTransform RasterTransformation of input raster
234 \param outRasterPtr output platter raster
235 \paeam palettesize number of colors of palette( default = 256)
236 */
237 Codifima(const te::rst::Raster& inputRaster,
238 te::map::RasterTransform& rasterTransform,
239 te::rst::Raster& outRasterPtr,
240 int palettesize = 256);
241
242 /*!
243 \brief Normal destructor
244 */
245 ~Codifima() { Clear(); }
246
247 /*!
248 \brief Aplies the method
249 \return true or false
250 */
251 bool Apply();
252
253 /*!
254 \brief Gets the generated palette
255 */
256 std::vector< te::rst::BandProperty::ColorEntry > getPalette() { return m_palette; }
257
258 protected:
259 const te::rst::Raster* m_inputRaster; //!< input rgb raster
260 te::map::RasterTransform* m_rasterTransform; //!< Raster Transformation from input raster
261 te::rst::Raster *m_outputRaster; //!< output palette raster
262 std::vector< te::rst::BandProperty::ColorEntry > m_palette; //!< generated palette
263
264 te::rst::Band *m_outBand; //!< output band
265
266 unsigned int m_outNCols; //!< output columns number
267 unsigned int m_outNRows; //!< output rows number
268
269 int m_ngc; //!< number of GroupColors
270 int m_firstvr, //!< fisrt valid red value
271 m_lastvr, //!< last valid red value
272 m_firstvg, //!< fisrt valid green value
273 m_lastvg, //!< last valid green value
274 m_firstvb, //!< fisrt valid blue value
275 m_lastvb; //!< last valid blue value
276
277 short m_blockr[256], //!< red grouping block
278 m_blockg[256], //!< green grouping block
279 m_blockb[256]; //!< blue grouping block
280 double **m_lut; //!< lut - values ​​found for each channel (R,G,B)
281 int m_finalcolors; //!< final number of colors found
282 GroupColor **m_GC; //!< array of GroupColors
283 std::list<CubeColor*> m_CClist; //!< list of CubeColors present in the Image
284 CubeColor ****hist; //!< histogram of CubeColors
285 int ***matclass; //!< classification matrix
286 };
287
288 } // end namespace rp
289} // end namespace te
290
291#endif
A Raster Transform is a class that defines functions to transform a styled raster.
Defines a Codifima class.
std::list< CubeColor * > m_CClist
list of CubeColors present in the Image
bool AllocateMatclass()
int m_firstvg
fisrt valid green value
te::map::RasterTransform * m_rasterTransform
Raster Transformation from input raster.
std::vector< te::rst::BandProperty::ColorEntry > getPalette()
Gets the generated palette.
std::vector< te::rst::BandProperty::ColorEntry > m_palette
generated palette
unsigned int m_outNCols
output columns number
unsigned int m_outNRows
output rows number
int m_ngc
number of GroupColors
CubeColor **** hist
histogram of CubeColors
double ** m_lut
lut - values ​​found for each channel (R,G,B)
Codifima(const te::rst::Raster &inputRaster, te::map::RasterTransform &rasterTransform, te::rst::Raster &outRasterPtr, int palettesize=256)
Codifies a rgb raster to a paletta raster.
int m_lastvr
last valid red value
void DeallocateMatclass()
int m_lastvg
last valid green value
bool Apply()
Aplies the method.
int m_firstvb
fisrt valid blue value
int *** matclass
classification matrix
bool image_codifying()
int m_firstvr
fisrt valid red value
const te::rst::Raster * m_inputRaster
input rgb raster
~Codifima()
Normal destructor.
int m_lastvb
last valid blue value
te::rst::Raster * m_outputRaster
output palette raster
te::rst::Band * m_outBand
output band
GroupColor ** m_GC
array of GroupColors
int m_finalcolors
final number of colors found
Defines a cubic volume in the RGB color space.
Definition: PaletteRaster.h:59
int IndexG()
Get green component of cube center.
Definition: PaletteRaster.h:93
void InsertTripleRGB(int r, int g, int b)
Inserts a triple rgb in CubeColor.
int m_igc
Index of GroupColor associated with CubeColor.
int IndexR()
Get red component of cube center.
Definition: PaletteRaster.h:87
double Pop()
Get number of Image rgb triples in the CubeColor.
int IndexB()
Get blue component of cube center.
Definition: PaletteRaster.h:99
double m_pop
Number of Image rgb triples in the CubeColor.
int m_ibg
Index of color green in the color cube space.
~CubeColor()
Destructor.
Definition: PaletteRaster.h:73
double Mean(int i)
Get i-th mean color component value.
CubeColor(int ir, int ig, int ib)
CubeColor constructor.
int m_ibb
Index of color blue in the color cube space.
void SetGroupColorIndex(int index)
Sets group color index.
int GroupColorIndex()
Get the index of GroupColor associated with CubeColor.
int m_ibr
Index of color red in the color cube space.
Defines a classification context.
GroupColor * Split(int newgcid)
Splits the GroupColor in two ones. The new GroupColor will have its id given by newgcid....
void InsertCubeColor(CubeColor *cc)
Inserts a CubeColor in the List.
double m_pop
population of group color
int m_id
Id of GroupColor.
GroupColor(int ident)
Constructor.
std::list< CubeColor * > m_CClist
List of pointers to CubeColors.
size_t GetNCubeColors()
Returns the number of CubeColors in this GroupColor.
double MaxVar()
Returns the biggest variance.
~GroupColor()
Destructor.
double Mean(int i)
Return Mean[i] of GroupColor.
std::list< CubeColor * >::iterator m_itCC
iterator to CubeColors list
CubeColor * RemoveCubeColor()
Removes the current item from the list.
double m_varmax
Biggest variance.
A raster band description.
Definition: Band.h:64
An abstract class for raster data strucutures.
Definition: Raster.h:72
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Proxy configuration file for TerraView (see terraview_config.h).