00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef IMAGE_COLORMAP_C_DEFINED
00039 #define IMAGE_COLORMAP_C_DEFINED
00040
00041 #include "Image/ColorMap.H"
00042
00043 #include "Image/MatrixOps.H"
00044 #include "Util/log.H"
00045
00046
00047 ColorMap::ColorMap() :
00048 Image< PixRGB<byte> >()
00049 { }
00050
00051
00052 ColorMap::ColorMap(const int n) :
00053 Image< PixRGB<byte> >(n, 1, NO_INIT)
00054 { }
00055
00056
00057 ColorMap::ColorMap(const Image< PixRGB<byte> >& cmap) :
00058 Image< PixRGB<byte> >(cmap.getHeight() != 1 ? transpose(cmap) : cmap)
00059 {
00060 if (this->getHeight() != 1) LFATAL("Invalid colormap image height != 1");
00061 }
00062
00063
00064 ColorMap::~ColorMap()
00065 { }
00066
00067
00068 ColorMap ColorMap::GREY(const int n)
00069 {
00070 Image< PixRGB<byte> > cmap(n, 1, NO_INIT);
00071 Image< PixRGB<byte> >::iterator ptr = cmap.beginw();
00072 for (int i = 0; i < n; i++)
00073 *ptr++ = PixRGB<byte>(byte((i * 256) / n));
00074 return ColorMap(cmap);
00075 }
00076
00077
00078 ColorMap ColorMap::GRADIENT(const PixRGB<byte>& from,
00079 const PixRGB<byte>& to,
00080 const int n)
00081 {
00082 Image< PixRGB<byte> > cmap(n, 1, NO_INIT);
00083 Image< PixRGB<byte> >::iterator ptr = cmap.beginw();
00084
00085 for (int i = 0; i < n; i++)
00086 *ptr++ = PixRGB<byte>(PixRGB<float>(from) +
00087 (PixRGB<float>(to) - PixRGB<float>(from)) *
00088 float(i) / float(n));
00089 return ColorMap(cmap);
00090 }
00091
00092
00093 ColorMap ColorMap::JET(const int m)
00094 {
00095 Image<PixRGB<byte> > cmap(m, 1, NO_INIT);
00096 const Image<PixRGB<byte> >::iterator ptr = cmap.beginw();
00097
00098 const int n = m/4;
00099 const int mid1 = n/2;
00100 const int mid2 = mid1 + n;
00101 const int mid3 = mid2 + n;
00102 const int mid4 = mid3 + n;
00103
00104 #define LINMAP(i, a_in, b_in, a_out, b_out) \
00105 byte(255.0 * ((a_out) \
00106 + double((i) - (a_in)) \
00107 * ((b_out)-(a_out)) \
00108 / ((b_in) - (a_in))))
00109
00110 for (int i = 0; i < mid1; ++i)
00111 ptr[i] = PixRGB<byte>(0,
00112 0,
00113 LINMAP(i, 0, mid1, 0.5, 1.0));
00114
00115 for (int i = mid1; i < mid2; ++i)
00116 ptr[i] = PixRGB<byte>(0,
00117 LINMAP(i, mid1, mid2, 0.0, 1.0),
00118 255);
00119
00120 for (int i = mid2; i < mid3; ++i)
00121 ptr[i] = PixRGB<byte>(LINMAP(i, mid2, mid3, 0.0, 1.0),
00122 255,
00123 LINMAP(i, mid2, mid3, 1.0, 0.0));
00124
00125 for (int i = mid3; i < mid4; ++i)
00126 ptr[i] = PixRGB<byte>(255,
00127 LINMAP(i, mid3, mid4, 1.0, 0.0),
00128 0);
00129
00130 for (int i = mid4; i < m; ++i)
00131 ptr[i] = PixRGB<byte>(LINMAP(i, mid4, m, 1.0, 0.5),
00132 0,
00133 0);
00134
00135 #undef LINMAP
00136
00137 return ColorMap(cmap);
00138 }
00139
00140 ColorMap ColorMap::LINES(const int m)
00141 {
00142 Image<PixRGB<byte> > cmap(m, 1, NO_INIT);
00143 const Image<PixRGB<byte> >::iterator ptr = cmap.beginw();
00144
00145 byte RValues[7] = {0, 0, 255, 0, 191, 191, 64};
00146 byte GValues[7] = {0, 128, 0, 191, 0, 191, 64};
00147 byte BValues[7] = {255, 0, 0, 191, 191, 0, 64};
00148
00149 if (m > 7*7*7)
00150 LFATAL("Only %i values are allowed for max", 7*7*7);
00151
00152 int i=0;
00153 for(int b=0; b<7; b++)
00154 for(int g=0; g<7; g++)
00155 for(int r=0; r<7; r++)
00156 {
00157 if (i >= m)
00158 break;
00159 ptr[i] = PixRGB<byte>(RValues[r],GValues[g],BValues[b]);
00160 i++;
00161 }
00162
00163 return ColorMap(cmap);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173 #endif // IMAGE_COLORMAP_C_DEFINED