40 #include <Utils/ColourGradient.hh>
41 #include <Base/Image/Image.hh>
42 #include <Base/Image/ImageIO.hh>
43 #include <Base/Image/ImageConvert.hh>
49 const bool SKIP_BLACK_PIXELS =
true;
54 int main(
int argc,
char* argv[])
59 <<
"Loads an image, recolours it and saves it." << endl << endl
61 << argv[0] <<
" <input_image> <output_image>" << endl << endl;
67 if (ImageIO::Load(argv[1], imageIn) != 0) {
68 cout <<
"loading image failed" << endl;
74 cout <<
"converting image to gray scale" << endl;
75 ImageConvert::IP_ToGrey(imageIn);
95 unsigned char* idaOut = imageOut.GetImageData();
96 vector<unsigned char> col(3);
98 for (
unsigned int y = 0; y < imageIn.
GetHeight(); ++y) {
99 for (
unsigned int x = 0; x < imageIn.
GetWidth(); ++x) {
100 const unsigned int offsetIn = y * imageIn.
GetWidth() + x;
101 const unsigned int offsetOut = y * imageIn.
GetWidth() * imageOut.GetChannelCount()
102 + x * imageOut.GetChannelCount();
104 const float curColFloat = float(idaIn[offsetIn]) / 255.0f;
105 if (!SKIP_BLACK_PIXELS || curColFloat != 0.0f) {
106 gradient.GetColour(curColFloat, col);
107 idaOut[offsetOut] = col[0];
108 idaOut[offsetOut + 1] = col[1];
109 idaOut[offsetOut + 2] = col[2];
115 ImageIO::Save(argv[2],
unsigned int GetWidth() const
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase