Commit 54021a37 authored by Emmanuel Christophe's avatar Emmanuel Christophe

ENH: add relief colormap functor

parent 393f20ae
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbReliefColormapFunctor_h
#define __otbReliefColormapFunctor_h
#include "itkColormapFunctor.h"
namespace otb {
namespace Functor {
/**
* \class ReliefColormapFunctor
* \brief Function object which maps a scalar value into an RGB colormap value for relief representation.
*
* This code is working with the framework contributed in the Insight Journal paper:
*
* "Meeting Andy Warhol Somewhere Over the Rainbow: RGB Colormapping and ITK"
* http://www.insight-journal.org/browse/publication/285
* http://hdl.handle.net/1926/1452
*
*/
template< class TScalar, class TRGBPixel >
class ITK_EXPORT ReliefColormapFunctor
: public itk::Functor::ColormapFunctor<TScalar, TRGBPixel>
{
public:
typedef ReliefColormapFunctor Self;
typedef itk::Functor::ColormapFunctor<TScalar, TRGBPixel> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro( Self );
typedef typename Superclass::RGBPixelType RGBPixelType;
typedef typename Superclass::ScalarType ScalarType;
typedef typename Superclass::RealType RealType;
virtual RGBPixelType operator()( const TScalar & ) const;
protected:
ReliefColormapFunctor(){};
~ReliefColormapFunctor() {};
private:
ReliefColormapFunctor(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace functor
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbReliefColormapFunctor.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbReliefColormapFunctor_txx
#define __otbReliefColormapFunctor_txx
#include "otbReliefColormapFunctor.h"
namespace otb {
namespace Functor {
template <class TScalar, class TRGBPixel>
typename ReliefColormapFunctor<TScalar, TRGBPixel>::RGBPixelType
ReliefColormapFunctor<TScalar, TRGBPixel>
::operator()( const TScalar & v ) const
{
float m_Borders[] = {0.0, 0.2, 0.43, 0.71, 1.0};
float m_RedValues[] = {0.2, 0.94, 0.74, 0.92, 1.0};
float m_GreenValues[] = {0.7, 0.98, 0.72, 0.86, 1.0};
float m_BlueValues[] = {0.2, 0.59, 0.53, 0.69, 1.0};
// Map the input scalar between [0, 1].
RealType value = this->RescaleInputValue( v );
int i = 1;
while (value > m_Borders[i]) i++;
float factor = (value-m_Borders[i-1]) / (m_Borders[i]-m_Borders[i-1]);
// Apply the color mapping.
RealType red = m_RedValues[i-1]+factor*(m_RedValues[i]-m_RedValues[i-1]);
RealType green = m_GreenValues[i-1]+factor*(m_GreenValues[i]-m_GreenValues[i-1]);
RealType blue = m_BlueValues[i-1]+factor*(m_BlueValues[i]-m_BlueValues[i-1]);
// Normalize the values
red = vnl_math_max( 0.0, red );
red = vnl_math_min( 1.0, red );
green = vnl_math_max( 0.0, green );
green = vnl_math_min( 1.0, green );
blue = vnl_math_max( 0.0, blue );
blue = vnl_math_min( 1.0, blue );
// Set the rgb components after rescaling the values.
RGBPixelType pixel;
pixel[0] = this->RescaleRGBComponentValue( red );
pixel[1] = this->RescaleRGBComponentValue( green );
pixel[2] = this->RescaleRGBComponentValue( blue );
return pixel;
}
} // end namespace Functor
} // end namespace otb
#endif
......@@ -35,8 +35,8 @@
// Software Guide : EndCommandLineArgs
// Software Guide : BeginCommandLineArgs
// OUTPUTS: {DEMToJetImageGenerator.png}
// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Examples/DEM_srtm jet
// OUTPUTS: {DEMToReliefImageGenerator.png}
// 6.5 45.5 500 500 0.002 -0.002 ${OTB_DATA_ROOT}/Examples/DEM_srtm relief
// Software Guide : EndCommandLineArgs
// Software Guide : BeginLatex
......@@ -62,7 +62,7 @@
#include "itkScalarToRGBColormapImageFilter.h"
#include "otbScalarToRainbowRGBPixelFunctor.h"
#include "otbDEMToImageGenerator.h"
#include "otbReliefColormapFunctor.h"
int main(int argc, char * argv[])
{
......@@ -141,7 +141,7 @@ int main(int argc, char * argv[])
else
{
if (strcmp(argv[8],"hot") == 0)
if (strcmp(argv[9],"hot") == 0)
{
typedef itk::Functor::HotColormapFunctor<PixelType, RGBPixelType> ColorMapFunctorType;
ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New();
......@@ -151,7 +151,7 @@ int main(int argc, char * argv[])
}
else
{
typedef itk::Functor::JetColormapFunctor<PixelType, RGBPixelType> ColorMapFunctorType;
typedef otb::Functor::ReliefColormapFunctor<PixelType, RGBPixelType> ColorMapFunctorType;
ColorMapFunctorType::Pointer colormap = ColorMapFunctorType::New();
colormap->SetMinimumInputValue(0);
colormap->SetMaximumInputValue(4000);
......@@ -192,7 +192,7 @@ int main(int argc, char * argv[])
// \includegraphics[width=0.44\textwidth]{pretty_DEMToImageGenerator.eps}
// \includegraphics[width=0.44\textwidth]{DEMToRainbowImageGenerator.eps}
// \includegraphics[width=0.44\textwidth]{DEMToHotImageGenerator.eps}
// \includegraphics[width=0.44\textwidth]{DEMToJetImageGenerator.eps}
// \includegraphics[width=0.44\textwidth]{DEMToReliefImageGenerator.eps}
// \itkcaption[Grayscale to color]{The gray level DEM extracted from SRTM
// data (top-left) and the same area in color representation.}
// \label{fig:RAINBOW_FILTER}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment