DGtal  0.9.2
exampleConstImageAdapter.cpp
1 
30 #include <iostream>
32 
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "ConfigExamples.h"
36 
37 #include "DGtal/io/boards/Board2D.h"
38 
40 #include "DGtal/io/colormaps/HueShadeColorMap.h"
41 #include "DGtal/io/colormaps/GrayscaleColorMap.h"
42 
43 #include "DGtal/images/ImageContainerBySTLVector.h"
44 #include "DGtal/images/ConstImageAdapter.h"
46 
48 
49 using namespace std;
50 using namespace DGtal;
52 
53 
55 template <typename Scalar>
56 struct LogScaleFunctor {
57 
58  LogScaleFunctor() {};
59  double operator()(const Scalar &a) const
60  {
61  return std::log( 1 + NumberTraits<Scalar>::castToDouble(a) );
62  }
63 
64 };
66 
67 
68 int main( /*int argc, char** argv*/ )
69 {
70  using namespace Z2i;
71 
72  Board2D aBoard;
73 
75  typedef HueShadeColorMap<unsigned char> HueShade; // a simple HueShadeColorMap varying on 'unsigned char' values
76  typedef HueShadeColorMap<double> HueShadeDouble; // a simple HueShadeColorMap varying on 'double' values
77  typedef GrayscaleColorMap<unsigned char> Gray; // a simple GrayscaleColorMap varying on 'unsigned char' values
78 
79  functors::Identity df; // a simple functor that just returns its argument
81 
82  trace.beginBlock("image");
83 
86  Domain domain(Point(1,1), Point(16,16));
87  Image image(domain);
89 
91  unsigned char i = 0;
92  for (Image::Iterator it = image.begin(); it != image.end(); ++it)
93  *it = i++;
95 
96  aBoard.clear();
97  Display2DFactory::drawImage<HueShade>(aBoard, image, (unsigned char)0, (unsigned char)255);
98  aBoard.saveSVG("image.svg");
99 
100  trace.endBlock();
101 
102  trace.beginBlock("subImage");
103 
106  Domain subDomain(Point(1,1), Point(8,8));
107  ConstImageAdapterForSubImage subImage(image, subDomain, df, df);
109 
110  aBoard.clear();
111  Display2DFactory::drawImage<HueShade>(aBoard, subImage, (unsigned char)0, (unsigned char)255);
112  aBoard.saveSVG("subImage.svg");
113 
114  trace.endBlock();
115 
116  trace.beginBlock("specificImage");
117 
119  DigitalSet set(domain);
120  for( unsigned int y=0; y < 17; y++)
121  for( unsigned int x=0; x < 17; x++)
122  if ((x%2) && (y%2))
123  set.insertNew(Point(x,y));
124 
125  DigitalSetDomain<DigitalSet> specificDomain(set);
127 
129  typedef ConstImageAdapter<Image, DigitalSetDomain<DigitalSet>, functors::Identity, Image::Value, functors::Identity > ConstImageAdapterForSpecificImage;
130  ConstImageAdapterForSpecificImage specificImage(image, specificDomain, df, df);
132 
133  aBoard.clear();
134  Display2DFactory::drawImage<HueShade>(aBoard, specificImage, (unsigned char)0, (unsigned char)255);
135  aBoard.saveSVG("specificImage.svg");
136 
137  trace.endBlock();
138 
139  trace.beginBlock("thresholderImage");
140 
144  ConstImageAdapterForThresholderImage thresholderImage(image, domain, df, t);
146 
147  aBoard.clear();
148  Display2DFactory::drawImage<Gray>(aBoard, thresholderImage, (unsigned char)0, (unsigned char)1);
149  aBoard.saveSVG("thresholderImage.svg");
150 
151  trace.endBlock();
152 
153  trace.beginBlock("logImage");
154 
157  LogScaleFunctor<Image::Value> logScale;
158  ConstImageAdapterForLogScale logImage(image, domain, df, logScale);
160 
161  aBoard.clear();
162  Display2DFactory::drawImage<HueShadeDouble>(aBoard, logImage, 0.0, logScale(255));
163  aBoard.saveSVG("logImage.svg");
164 
165  trace.endBlock();
166 
167  return 0;
168 }
169 // //
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: Define a simple default functor that just returns its argument.
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70