iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColorMap.H
Go to the documentation of this file.
1 /*! @file
2  @author Zhihao Li
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #ifndef INCLUDE_NRT_IMAGEPROC_COLOR_COLORMAP_H
36 #define INCLUDE_NRT_IMAGEPROC_COLOR_COLORMAP_H
37 
39 #include <nrt/Core/Image/Image.H>
41 
42 namespace nrt
43 {
44  //! Simple colormaps with N colors
45  /*! ColorMap derives from Image< PixRGB<byte> > and hence inherits all
46  the associated functions. Here we just provide a bunch of
47  constructors. A ColorMap then is merely an Image< PixRGB<byte> > of
48  width N and height 1. */
49  class ColorMap : public Image< PixRGB<byte> > {
50  public:
51 
52  //! Default constructor (empty colormap)
53  ColorMap();
54 
55  //! Default constructor (uninitialized color values, n entries)
56  ColorMap(const int n);
57 
58  //! Build from an Image of pixels (used by the pseudo-constructors)
59  /*! Will throw a fatal error if cmap has height != 1 */
60  ColorMap(const Image< PixRGB<byte> >& cmap);
61 
62  //! Destructor
63  virtual ~ColorMap();
64 
65  //! Pseudo-constructor for a greyscale with n entries
66  static ColorMap GREY(const int n = 256);
67 
68  //! Pseudo-constructor for a transition from 'from' to 'to' with n entries
69  static ColorMap GRADIENT(const PixRGB<byte>& from,
70  const PixRGB<byte>& to,
71  const int n = 256);
72 
73  //! Pseudo-constructor for "jet" colormap a la matlab
74  static ColorMap JET(const int n = 256);
75 
76  //! Pseudo-constructor for "lines" colormap a la matlab
77  static ColorMap LINES(const int n = 256);
78  };
79 
80  //! Convert a scalar value to a color using a specified colormap
81  template<class T>
82  PixRGB<byte> applyColorMapToPixel(T v, T vmin, T vmax, ColorMap const & cm);
83 
84  //! Colorize a grayscale image using a specified colormap
85  template<class T>
86  Image<PixRGB<byte>> applyColorMap(Image<PixGray<T>> const & input, T min, T max, ColorMap const & cm);
87 
88 }
89 
91 
92 #endif // INCLUDE_NRT_IMAGEPROC_COLOR_COLORMAP_H