<commit_before>/*=========================================================================

 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.

 =========================================================================*/
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"


#include <fstream>

// Include differents method for color mapping
#include "otbChangeLabelImageFilter.h"
#include "itkLabelToRGBImageFilter.h"
#include "itkScalarToRGBColormapImageFilter.h"
#include "otbReliefColormapFunctor.h"

namespace otb
{
namespace Wrapper
{

class ColorMapping: public Application
{
public:
/** Standard class typedefs. */
  typedef ColorMapping      Self;
  typedef Application                   Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

  /** Standard macro */
  itkNewMacro(Self);

  itkTypeMacro(ColorMapping, otb::Application);

  typedef FloatImageType::PixelType   PixelType;
  typedef UInt16ImageType             LabelImageType;
  typedef LabelImageType::PixelType   LabelType;
  typedef UInt8VectorImageType        VectorImageType;
  typedef VectorImageType::PixelType  VectorPixelType;
  typedef UInt8RGBImageType           RGBImageType;
  typedef RGBImageType::PixelType     RGBPixelType;

  // Manual label LUT
  typedef otb::ChangeLabelImageFilter
  <LabelImageType,VectorImageType>    ChangeLabelFilterType;

  // Segmentation contrast maximisation LUT
  typedef itk::LabelToRGBImageFilter
  <LabelImageType,RGBImageType>       LabelToRGBFilterType;

  // Continuous LUT mapping
  typedef itk::ScalarToRGBColormapImageFilter
  <FloatImageType, RGBImageType>      ColorMapFilterType;
  typedef otb::Functor::ReliefColormapFunctor
  <PixelType, RGBPixelType>           ReliefColorMapFunctorType;

private:
  ColorMapping()
  {
    SetName("ColorMapping");
    SetDescription("Maps an input grayscale image into 8-bits RGB using look-up tables.");

    SetDocName("Color Mapping");
    SetDocLongDescription("");
    SetDocLimitations("None");
    SetDocAuthors("OTB-Team");
    SetDocSeeAlso(" ");
    SetDocCLExample("otbApplicationLauncherCommandLine ColorMapping   --in ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif --ct ${OTB-Data}/Input/Classification/ColorTable.txt --out clLabeledFancyImageQB123_1.tif");
    AddDocTag(Tags::Learning);

    // Build lut map

    m_LutMap["Red"]=ColorMapFilterType::Red;
    m_LutMap["Green"]=ColorMapFilterType::Green;
    m_LutMap["Blue"]=ColorMapFilterType::Blue;
    m_LutMap["Grey"]=ColorMapFilterType::Grey;
    m_LutMap["Hot"]=ColorMapFilterType::Hot;
    m_LutMap["Cool"]=ColorMapFilterType::Cool;
    m_LutMap["Spring"]=ColorMapFilterType::Spring;
    m_LutMap["Summer"]=ColorMapFilterType::Summer;
    m_LutMap["Autumn"]=ColorMapFilterType::Autumn;
    m_LutMap["Winter"]=ColorMapFilterType::Winter;
    m_LutMap["Copper"]=ColorMapFilterType::Copper;
    m_LutMap["Jet"]=ColorMapFilterType::Jet;
    m_LutMap["HSV"]=ColorMapFilterType::HSV;
    m_LutMap["OverUnder"]=ColorMapFilterType::OverUnder;
  }

  virtual ~ColorMapping()
  {
  }

  void DoCreateParameters()
  {
    AddParameter(ParameterType_InputImage, "in", "Input Image");
    SetParameterDescription("in", "Input image filename.");
    AddParameter(ParameterType_OutputImage, "out", "Output Image");
    SetParameterDescription("out","Output image filename.");
    AddParameter(ParameterType_RAM, "ram", "Available RAM");
    SetDefaultParameterInt("ram", 256);
    MandatoryOff("ram");


    AddParameter(ParameterType_Choice, "method", "Color mapping method");
    SetParameterDescription("method","Selection of color mapping methods and their parameters.");
    // Custom LUT
    AddChoice("method.custom","Color mapping with custom labeled look-up table");
    SetParameterDescription("method.custom","Apply a user-defined look-up table to a labeled image. Look-up table is loaded from a text file.");
    AddParameter(ParameterType_Filename, "method.custom.lut", "Look-up table file");
    SetParameterDescription("method.custom.lut",  "An ASCII file containing the look-up table\n"
                            "with one color per line\n"
                            "(for instance the line '1 255 0 0' means that all pixels with label 1 will be replaced by RGB color 255 0 0)\n"
                            "Lines beginning with a # are ignored");

    // Continuous LUT
    AddChoice("method.continuous","Color mapping with continuous look-up table");
    SetParameterDescription("method.continuous","Apply a continuous look-up table to a range of input values.");
    AddParameter(ParameterType_Choice,"method.continuous.lut","Look-up tables");
    SetParameterDescription("method.continuous.lut","Available look-up tables.");

    AddChoice("method.continuous.lut.red","Red");
    AddChoice("method.continuous.lut.green","Green");
    AddChoice("method.continuous.lut.blue","Blue");
    AddChoice("method.continuous.lut.grey","Grey");
    AddChoice("method.continuous.lut.hot","Hot");
    AddChoice("method.continuous.lut.cool","Cool");
    AddChoice("method.continuous.lut.spring","Spring");<commit_msg>DOC: Enhancing documentation of the new ColorMapping application<commit_after>/*=========================================================================

 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.

 =========================================================================*/
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"


#include <fstream>

// Include differents method for color mapping
#include "otbChangeLabelImageFilter.h"
#include "itkLabelToRGBImageFilter.h"
#include "itkScalarToRGBColormapImageFilter.h"
#include "otbReliefColormapFunctor.h"

namespace otb
{
namespace Wrapper
{

class ColorMapping: public Application
{
public:
/** Standard class typedefs. */
  typedef ColorMapping      Self;
  typedef Application                   Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

  /** Standard macro */
  itkNewMacro(Self);

  itkTypeMacro(ColorMapping, otb::Application);

  typedef FloatImageType::PixelType   PixelType;
  typedef UInt16ImageType             LabelImageType;
  typedef LabelImageType::PixelType   LabelType;
  typedef UInt8VectorImageType        VectorImageType;
  typedef VectorImageType::PixelType  VectorPixelType;
  typedef UInt8RGBImageType           RGBImageType;
  typedef RGBImageType::PixelType     RGBPixelType;

  // Manual label LUT
  typedef otb::ChangeLabelImageFilter
  <LabelImageType,VectorImageType>    ChangeLabelFilterType;

  // Segmentation contrast maximisation LUT
  typedef itk::LabelToRGBImageFilter
  <LabelImageType,RGBImageType>       LabelToRGBFilterType;

  // Continuous LUT mapping
  typedef itk::ScalarToRGBColormapImageFilter
  <FloatImageType, RGBImageType>      ColorMapFilterType;
  typedef otb::Functor::ReliefColormapFunctor
  <PixelType, RGBPixelType>           ReliefColorMapFunctorType;

private:
  ColorMapping()
  {
    SetName("ColorMapping");
    SetDescription("Maps an input grayscale image into 8-bits RGB using look-up tables.");

    SetDocName("Color Mapping");
    SetDocLongDescription("This application allows to map an input grayscale into a 8-bits RGB image using three different methods.\n" "-The custom method allows to apply a custom look-up table to a labeled image. The look-up table is loaded from a text file where each line describes an entry. The typical use of this method is to colorise a classification map.\n" "-The continuous method allows to map a range of values in a scalar input image into a colored image using continuous look-up table, in order to enhance image interpretation. Several look-up tables can ben chosen with different color ranges.\n" "-The segmentation method is dedicated to segmentation labeled outputs where each segment correspond to a unique labeled. It computes an optimal look-up table such that color difference between adjacent segmented regions is maximised.");
    SetDocLimitations("The segmentation method does not support streaming, and thus large images.");
    SetDocAuthors("OTB-Team");
    SetDocSeeAlso("ImageSVMClassifier application");
    SetDocCLExample("otbApplicationLauncherCommandLine ColorMapping  --in ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif --method custom --method.custom.lut ${OTB-Data}/Input/Classification/ColorTable.txt --out clLabeledFancyImageQB123_1.tif");
    AddDocTag(Tags::Learning);

    // Build lut map

    m_LutMap["Red"]=ColorMapFilterType::Red;
    m_LutMap["Green"]=ColorMapFilterType::Green;
    m_LutMap["Blue"]=ColorMapFilterType::Blue;
    m_LutMap["Grey"]=ColorMapFilterType::Grey;
    m_LutMap["Hot"]=ColorMapFilterType::Hot;
    m_LutMap["Cool"]=ColorMapFilterType::Cool;
    m_LutMap["Spring"]=ColorMapFilterType::Spring;
    m_LutMap["Summer"]=ColorMapFilterType::Summer;
    m_LutMap["Autumn"]=ColorMapFilterType::Autumn;
    m_LutMap["Winter"]=ColorMapFilterType::Winter;
    m_LutMap["Copper"]=ColorMapFilterType::Copper;
    m_LutMap["Jet"]=ColorMapFilterType::Jet;
    m_LutMap["HSV"]=ColorMapFilterType::HSV;
    m_LutMap["OverUnder"]=ColorMapFilterType::OverUnder;
  }

  virtual ~ColorMapping()
  {
  }

  void DoCreateParameters()
  {
    AddParameter(ParameterType_InputImage, "in", "Input Image");
    SetParameterDescription("in", "Input image filename");
    AddParameter(ParameterType_OutputImage, "out", "Output Image");
    SetParameterDescription("out","Output image filename");
    AddParameter(ParameterType_RAM, "ram", "Available RAM");
    SetDefaultParameterInt("ram", 256);
    MandatoryOff("ram");


    AddParameter(ParameterType_Choice, "method", "Color mapping method");
    SetParameterDescription("method","Selection of color mapping methods and their parameters.");

    // Custom LUT
    AddChoice("method.custom","Color mapping with custom labeled look-up table");
    SetParameterDescription("method.custom","Apply a user-defined look-up table to a labeled image. Look-up table is loaded from a text file.");
    AddParameter(ParameterType_Filename, "method.custom.lut", "Look-up table file");
    SetParameterDescription("method.custom.lut",  "An ASCII file containing the look-up table\n"
                            "with one color per line\n"
                            "(for instance the line '1 255 0 0' means that all pixels with label 1 will be replaced by RGB color 255 0 0)\n"
                            "Lines beginning with a # are ignored");

    // Continuous LUT
    AddChoice("method.continuous","Color mapping with continuous look-up table");
    SetParameterDescription("method.continuous","Apply a continuous look-up table to a range of input values.");
    AddParameter(ParameterType_Choice,"method.continuous.lut","Look-up tables");
    SetParameterDescription("method.continuous.lut","Available look-up tables.");

    AddChoice("method.continuous.lut.red","Red");
    AddChoice("method.continuous.lut.green","Green");
    AddChoice("method.continuous.lut.blue","Blue");
    AddChoice("method.continuous.lut.grey","Grey");
    AddChoice("method.continuous.lut.hot","Hot");
    AddChoice("method.continuous.lut.cool","Cool");
    AddChoice("method.continuous.lut.spring","Spring");
{'fraction_non_alphanumeric': 0.12697616060225847, 'fraction_numerical': 0.004767879548306148, 'mean_word_length': 4.731543624161074, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644122', 'n_tokens_mistral': 3473, 'n_tokens_neox': 3239, 'n_words': 828}