DGtal  1.3.beta
images/exampleConstImageAdapter.cpp

Example of ConstImageAdapter.

See also
ConstImageAdapter
16x16 image: (1,1) to (16,16) adapted from with a log scale functor.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ConstImageAdapter.h"
using namespace std;
using namespace DGtal;
template <typename Scalar>
struct LogScaleFunctor {
LogScaleFunctor() {};
double operator()(const Scalar &a) const
{
return std::log( 1 + NumberTraits<Scalar>::castToDouble(a) );
}
};
int main( /*int argc, char** argv*/ )
{
using namespace Z2i;
Board2D aBoard;
typedef HueShadeColorMap<unsigned char> HueShade; // a simple HueShadeColorMap varying on 'unsigned char' values
typedef HueShadeColorMap<double> HueShadeDouble; // a simple HueShadeColorMap varying on 'double' values
typedef GrayscaleColorMap<unsigned char> Gray; // a simple GrayscaleColorMap varying on 'unsigned char' values
functors::Identity df; // a simple functor that just returns its argument
trace.beginBlock("image");
Domain domain(Point(1,1), Point(16,16));
unsigned char i = 0;
for (Image::Iterator it = image.begin(); it != image.end(); ++it)
*it = i++;
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, image, (unsigned char)0, (unsigned char)255);
aBoard.saveSVG("image.svg");
trace.beginBlock("subImage");
Domain subDomain(Point(1,1), Point(8,8));
ConstImageAdapterForSubImage subImage(image, subDomain, df, df);
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, subImage, (unsigned char)0, (unsigned char)255);
aBoard.saveSVG("subImage.svg");
trace.beginBlock("specificImage");
for( unsigned int y=0; y < 17; y++)
for( unsigned int x=0; x < 17; x++)
if ((x%2) && (y%2))
set.insertNew(Point(x,y));
DigitalSetDomain<DigitalSet> specificDomain(set);
ConstImageAdapterForSpecificImage specificImage(image, specificDomain, df, df);
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, specificImage, (unsigned char)0, (unsigned char)255);
aBoard.saveSVG("specificImage.svg");
trace.beginBlock("thresholderImage");
ConstImageAdapterForThresholderImage thresholderImage(image, domain, df, t);
aBoard.clear();
Display2DFactory::drawImage<Gray>(aBoard, thresholderImage, (unsigned char)0, (unsigned char)1);
aBoard.saveSVG("thresholderImage.svg");
trace.beginBlock("logImage");
LogScaleFunctor<Image::Value> logScale;
ConstImageAdapterForLogScale logImage(image, domain, df, logScale);
aBoard.clear();
Display2DFactory::drawImage<HueShadeDouble>(aBoard, logImage, 0.0, logScale(255));
aBoard.saveSVG("logImage.svg");
return 0;
}
// //
DGtal::functors::Thresholder
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
Definition: BasicFunctors.h:500
DGtal::GrayscaleColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Definition: GrayscaleColorMap.h:93
image
Image image(domain)
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:531
DGtal::HueShadeColorMap< unsigned char >
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition: BasicFunctors.h:287
DGtal::ConstImageAdapter
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Definition: ConstImageAdapter.h:105
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition: ImageContainerBySTLVector.h:264
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
domain
Domain domain
Definition: testProjection.cpp:88
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::DigitalSetDomain< DigitalSet >
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38