Example of ConstImageAdapter.
#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;
template <typename Scalar>
struct LogScaleFunctor {
LogScaleFunctor() {};
double operator()(const Scalar &a) const
{
return std::log( 1 + NumberTraits<Scalar>::castToDouble(a) );
}
};
{
using namespace Z2i;
Board2D aBoard;
typedef HueShadeColorMap<unsigned char> HueShade;
typedef HueShadeColorMap<double> HueShadeDouble;
typedef GrayscaleColorMap<unsigned char> Gray;
functors::Identity df;
typedef ImageContainerBySTLVector<Domain, unsigned char>
Image;
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");
typedef ConstImageAdapter<Image, Domain, functors::Identity, Image::Value, functors::Identity > ConstImageAdapterForSubImage;
ConstImageAdapterForSubImage subImage(image, subDomain, df, df);
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, subImage, (unsigned char)0, (unsigned char)255);
aBoard.saveSVG("subImage.svg");
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);
typedef ConstImageAdapter<Image, DigitalSetDomain<DigitalSet>, functors::Identity,
Image::Value, functors::Identity > ConstImageAdapterForSpecificImage;
ConstImageAdapterForSpecificImage specificImage(image, specificDomain, df, df);
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, specificImage, (unsigned char)0, (unsigned char)255);
aBoard.saveSVG("specificImage.svg");
typedef ConstImageAdapter<Image, Domain, functors::Identity, bool, DGtal::functors::Thresholder<Image::Value> > ConstImageAdapterForThresholderImage;
ConstImageAdapterForThresholderImage thresholderImage(image,
domain, df, t);
aBoard.clear();
Display2DFactory::drawImage<Gray>(aBoard, thresholderImage, (unsigned char)0, (unsigned char)1);
aBoard.saveSVG("thresholderImage.svg");
typedef ConstImageAdapter<Image, Domain, functors::Identity, double, LogScaleFunctor<Image::Value> > ConstImageAdapterForLogScale;
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;
}
void beginBlock(const std::string &keyword="")
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet