Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ColourMap.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2013 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include "ColourMap.hh"
26 
27 using namespace std;
28 using namespace BIAS;
29 
30 
31 void ColourMap::Apply(const Image<float>& imageIn,
32  Image<unsigned char>& imageOut)
33 {
34  // assertions
35  BIASASSERT(imageIn.GetChannelCount());
36 
37  // copy and normalise input image
38  Image<float> imageInNorm(imageIn);
39  imageInNorm.ScaleShiftBetween(0, 1);
40 
41  // create output image
42  imageOut.Init(imageInNorm.GetWidth(), imageInNorm.GetHeight(), 3);
43 
44  // get data pointers
45  const float* imageInData = imageInNorm.GetImageData();
46  unsigned char* imageOutData = imageOut.GetImageData();
47 
48  // apply colour map
49  for (size_t y = 0; y < imageInNorm.GetHeight(); ++y)
50  {
51  for (size_t x = 0; x < imageInNorm.GetWidth(); ++x)
52  {
53  const size_t offsetIn = y * imageInNorm.GetWidth() + x;
54  const size_t offsetOut = y * imageInNorm.GetWidth() * imageOut.GetChannelCount()
55  + x * imageOut.GetChannelCount();
56 
57  const float curValue = imageInData[offsetIn];
58 
59  vector<unsigned char> curColour;
60  m_mapGradient.GetColour(curValue, curColour);
61 
62  imageOutData[offsetOut] = curColour[0];
63  imageOutData[offsetOut + 1] = curColour[1];
64  imageOutData[offsetOut + 2] = curColour[2];
65  }
66  }
67 }
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137