ThermalToColorOperator.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  ThermalToColorOperator.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Additional information:
00008  *  $Id: ThermalToColorOperator.cpp 44313 2011-04-06 22:46:28Z agas $ 
00009  *******************************************************************************/
00010 
00011 #include "ThermalToColorOperator.h"
00012 #include <iostream>
00013 using namespace std;
00014 
00015 namespace puma2 {
00016 
00017 ThermalToColorOperator::ThermalToColorOperator(const GrayLevelImage8& constThermalImage, ColorImageRGB8& imageRGB, int thermalMin, int thermalMax)
00018 {
00019   m_ThermalMin=thermalMin;
00020   m_ThermalMax=thermalMax;
00021   checkArgument(constThermalImage, imageRGB);
00022   apply(constThermalImage, imageRGB);
00023 }
00024     
00025 void ThermalToColorOperator::apply(const GrayLevelImage8& constThermalImage, ColorImageRGB8& imageRGB)
00026 {
00027   
00028   GrayLevelImage8& thermalImage=const_cast<GrayLevelImage8&>(constThermalImage);
00029 
00030   int width=imageRGB.getWidth();
00031   int height=imageRGB.getHeight();
00032 
00033   puma2::byte** thermalRow = thermalImage.unsafeRowPointerArray();
00034   ColorImageRGB8::PixelType** rgbRow = imageRGB.unsafeRowPointerArray();
00035   
00036   //ptr. to current row in orig. image
00037   puma2::byte* currentThermalRow;
00038   ColorImageRGB8::PixelType* currentRgbRow;
00039   
00040   unsigned char rPalette[256];
00041   unsigned char gPalette[256];
00042   unsigned char bPalette[256];
00043 
00044   //create palette (blue-green-red)
00045   int t, t2;
00046   
00047   for (int i=0; i<256; i++) {
00048     t=(i-m_ThermalMin)*255/(m_ThermalMax-m_ThermalMin);
00049     if (t < 0) t=0;
00050     if (t > 255) t=255;
00051     if (t<128) {
00052       t2=t*2;
00053       rPalette[i]=0;
00054       gPalette[i]=t2;
00055       bPalette[i]=255-t2;
00056     } else {
00057       t2=(t-128)*2;
00058       rPalette[i]=t2;
00059       gPalette[i]=255-t2;
00060       bPalette[i]=0;
00061     }
00062   }
00063   
00064   //convert image
00065   unsigned int currentThermalSample;
00066   int x,y;
00067   for( y = 0; y < height ; y++ ) {
00068     currentThermalRow=thermalRow[y];
00069     currentRgbRow=rgbRow[y];
00070     for( x = 0; x < width ; x++ ) {
00071       currentThermalSample=currentThermalRow[x];
00072       currentRgbRow[x][0]=rPalette[ currentThermalSample ];
00073       currentRgbRow[x][1]=gPalette[ currentThermalSample ];
00074       currentRgbRow[x][2]=bPalette[ currentThermalSample ];
00075     }
00076   }
00077   
00078 }
00079 
00080 }
00081 


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43