eLynx SDK v3.3.0
C++ image processing API reference

How to add image services?

Here is a trip into image classes.


To illustrate the tutorial we are going to add the Colorize filter.

Follow these steps:


Select the interface where the functionnality will be added

In our sample, colorize is a point to point processing filter, so we use IImagePointProcessing interface.

You can choose beetween:

Go to top


Declare the functionnality in the interface using AbstractImage as a pure virtual method

In file eLynx/include/elx/image/IImagePointProcessing.h add:

// Colorize an image setting a hue and saturation.
// <table border=0><tr>
// <td><center><img src="res/image/color.original.png"><br><img src="res/image/ramps.original.png"><br>original</center></td>
// <td><center><img src="res/image/color.Colorize.png"><br><img src="res/image/ramps.Colorize.png"><br>Colorize(0.27, 0.21) with Sepia tone</center><td>
// </tr></table>  
// @param ioImage image to process.
// @param iHue Hue in normalised range [0.0, 1.0].
// @param iSaturation Saturation in normalised range [0.0, 1.0].
// @param iNotifier a notifier for progression, log and cancel.
// @return Method running status.
virtual bool Colorize(AbstractImage& ioImage,
  double iHue, double iSaturation, 
  ProgressNotifier& iNotifier) const = 0;

Go to top


Declare the functionnality in the interface implementation

We declare method:

In file eLynx/include/elx/image/ImagePointProcessingImpl.h add:

virtual bool Colorize(AbstractImage& ioImage,
  double iHue, double iSaturation, 
  ProgressNotifier& iNotifier) const;
  
static bool Colorize(ImageImpl<Pixel>& ioImage,
  double iHue, double iSaturation, 
  ProgressNotifier& iNotifier=ProgressNotifier_NULL);

Go to top


Implement the functionnality in implementation file

//============================================================================
//  PointProcessing/Colorize.hpp                       Image.Component package
//============================================================================
//  Copyright (C) 2007 by eLynx project
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Library General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//  See the GNU Library General Public License for more details.
//----------------------------------------------------------------------------
#ifndef __PointProcessing_Colorize_hpp__
#define __PointProcessing_Colorize_hpp__

namespace eLynx {
namespace Image {

//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
//                    static specialized services
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

//----------------------------------------------------------------------------
//  Colorize
//----------------------------------------------------------------------------
template <typename Pixel>
bool ImagePointProcessingImpl<Pixel>::Colorize(
    ImageImpl< Pixel >& ioImage,
    double iHue, 
    double iSaturation, 
    ProgressNotifier& iNotifier)
{
  // TODO
  return false;

} // Colorize


//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
//          virtual from ImagePointProcessingImpl implementation
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

//----------------------------------------------------------------------------
//  Colorize
//----------------------------------------------------------------------------
template <typename Pixel>
bool ImagePointProcessingImpl<Pixel>::Colorize(
    AbstractImage& ioImage,
    double iHue, 
    double iSaturation, 
    ProgressNotifier& iNotifier) const
{
  // TODO
  return false;
  
} // Colorize

} // namespace Image
} // namespace eLynx

#endif // __PointProcessing_Colorize_hpp__
//----------------------------------------------------------------------------
//  Colorize
//----------------------------------------------------------------------------
template <typename Pixel>
bool ImagePointProcessingImpl<Pixel>::Colorize(
    ImageImpl<Pixel>& ioImage,
    double iHue, 
    double iSaturation, 
    ProgressNotifier& iNotifier)
{
  typedef typename Pixel::type T;
  if (!ioImage.IsValid()) return false;

  Pixel * prDst = ioImage.GetPixel();
  Pixel * prEnd = ioImage.GetPixelEnd();

  T hue = elxGetHue<T>(iHue);
  T saturation = elxGetSaturation<T>(iSaturation);
  do 
  { 
    elxColorize(*prDst, hue, saturation); 
  }
  while (++prDst != prEnd);

  return true;

} // Colorize
//----------------------------------------------------------------------------
//  Colorize
//----------------------------------------------------------------------------
template <typename Pixel>
bool ImagePointProcessingImpl<Pixel>::Colorize(
    AbstractImage& ioImage,
    double iHue, 
    double iSaturation, 
    ProgressNotifier& iNotifier) const
{
  ImageImpl<Pixel>& image = elxDowncast<Pixel>(ioImage);
  return Colorize(image, iHue, iSaturation, iNotifier);

} // Colorize

Go to top


Instanciante implementation for all pixels types

We just need to add In file eLynx/src/Image/ImagePointProcessingImpl.cpp, instanciation is done invoking the macro :

elxINSTANTIATE_CLASS_FOR_ALL_PIXEL_TYPES( ImagePointProcessingImpl );

We just need to include implementation file before:

#include "PointProcessing/Colorize.hpp"

Go to top


Declare and implement the functionnality for ImageVariant class

// Colorize an image setting a hue and saturation.
// <table border=0><tr>
// <td><center><img src="res/image/color.original.png"><br><img src="res/image/ramps.original.png"><br>original</center></td>
// <td><center><img src="res/image/color.Colorize.png"><br><img src="res/image/ramps.Colorize.png"><br>Colorize(0.27, 0.21) with Sepia tone</center><td>
// </tr></table>
// @param iHue Hue in normalised range [0.0, 1.0].
// @param iSaturation Saturation in normalised range [0.0, 1.0].
// @param iNotifier a notifier for progression, log and cancel.
// @return Method running status.
bool Colorize(double iHue, double iSaturation, 
  ProgressNotifier& iNotifier=ProgressNotifier_NULL);
//----------------------------------------------------------------------------
//  Colorize
//----------------------------------------------------------------------------
bool ImageVariant::Colorize(double iHue, double iSaturation, 
    ProgressNotifier& iNotifier)
{
  if (NULL == _spAbstractImpl.get()) return false;
  
  // do not support Bayer image
  if (IsBayer()) return false;

  return elxGetPointToPointHandler(*_spAbstractImpl).
    Colorize(*_spAbstractImpl, iHue, iSaturation, iNotifier);

} // Colorize

Go to top


Generated on Thu Dec 9 2010 by doxygen 1.7.2