Skip to content
Snippets Groups Projects
Commit 0ece6466 authored by Victor Poughon's avatar Victor Poughon
Browse files

DOC: review IndexedToRGBExample

parent b5527446
Branches
Tags
No related merge requests found
Data/Output/buildingExtractionIndexed_scaled.png

130 B

Data/Output/buildingExtractionRGB.png

130 B

......@@ -24,25 +24,11 @@
*/
// Some algorithms produce an indexed image as output. In such images,
// each pixel is given a value according to the region number it belongs to.
// This value starting at 0 or 1 is usually an integer value.
// Often, such images are produced by segmentation or classification algorithms.
//
// If such regions are easy to manipulate -- it is easier and faster to compare two integers
// than a RGB value -- it is different when it comes to displaying the results.
//
// Here we present a convient way to convert such indexed image to a color image. In
// such conversion, it is important to ensure that neighborhood region, which are
// likely to have consecutive number have easily dicernable colors. This is done
// randomly using a hash function by the \doxygen{itk}{ScalarToRGBPixelFunctor}.
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "itkUnaryFunctorImageFilter.h"
#include "itkScalarToRGBPixelFunctor.h"
#include "itkRescaleIntensityImageFilter.h"
int main(int argc, char* argv[])
......@@ -65,10 +51,8 @@ int main(int argc, char* argv[])
reader->SetFileName(inputFilename);
// The \doxygen{itk}{UnaryFunctorImageFilter} is the filter in charge of
// calling the functor we specify to do the work for each pixel. Here it is the
// \doxygen{itk}{ScalarToRGBPixelFunctor}.
// The UnaryFunctorImageFilter is the filter in charge of calling the functor
// we specify to do the work for each pixel. Here it is the ScalarToRGBPixelFunctor
typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType;
typedef itk::UnaryFunctorImageFilter<ImageType, RGBImageType, ColorMapFunctorType> ColorMapFilterType;
ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();
......@@ -93,17 +77,4 @@ int main(int argc, char* argv[])
writer2->SetFileName(outputScaledFilename);
writer2->SetInput(rescaler->GetOutput());
writer2->Update();
// Figure~\ref{fig:INDEXTORGB_FILTER} shows the result of the conversion
// from an indexed image to a color image.
// \begin{figure}
// \center
// \includegraphics[width=0.44\textwidth]{buildingExtractionIndexed_scaled.eps}
// \includegraphics[width=0.44\textwidth]{buildingExtractionRGB.eps}
// \itkcaption[Scaling images]{The original indexed image (left) and the
// conversion to color image.}
// \label{fig:INDEXTORGB_FILTER}
// \end{figure}
return EXIT_SUCCESS;
}
Some algorithms produce an indexed image as output. In such images,
each pixel is given a value according to the region number it belongs to.
This value starting at 0 or 1 is usually an integer value.
Often, such images are produced by segmentation or classification algorithms.
If such regions are easy to manipulate -- it is easier and faster to compare two integers
than a RGB value -- it is different when it comes to displaying the results.
Here we present a convient way to convert such indexed image to a color image. In
such conversion, it is important to ensure that neighborhood region, which are
likely to have consecutive number have easily dicernable colors. This is done
randomly using a hash function by ``ScalarToRGBPixelFunctor``.
.. |image1| image:: /Output/buildingExtractionIndexed_scaled.png
.. |image2| image:: /Output/buildingExtractionRGB.png
.. _Figure1:
+--------------------------+-------------------------+
| |image1| | |image2| |
+--------------------------+-------------------------+
The original indexed image (left) and the conversion to color image.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment