DGtal 1.3.0
Loading...
Searching...
No Matches
exampleConstImageAdapter.cpp
Go to the documentation of this file.
1
39#include <iostream>
40
41#include "DGtal/base/Common.h"
42#include "DGtal/helpers/StdDefs.h"
43#include "ConfigExamples.h"
44
45#include "DGtal/io/boards/Board2D.h"
46
48#include "DGtal/io/colormaps/HueShadeColorMap.h"
49#include "DGtal/io/colormaps/GrayscaleColorMap.h"
50
51#include "DGtal/images/ImageContainerBySTLVector.h"
52#include "DGtal/images/ConstImageAdapter.h"
54
56
57using namespace std;
58using namespace DGtal;
60
61
63template <typename Scalar>
64struct LogScaleFunctor {
65
66 LogScaleFunctor() {};
67 double operator()(const Scalar &a) const
68 {
69 return std::log( 1 + NumberTraits<Scalar>::castToDouble(a) );
70 }
71
72};
74
75
76int main( /*int argc, char** argv*/ )
77{
78 using namespace Z2i;
79
80 Board2D aBoard;
81
83 typedef HueShadeColorMap<unsigned char> HueShade; // a simple HueShadeColorMap varying on 'unsigned char' values
84 typedef HueShadeColorMap<double> HueShadeDouble; // a simple HueShadeColorMap varying on 'double' values
85 typedef GrayscaleColorMap<unsigned char> Gray; // a simple GrayscaleColorMap varying on 'unsigned char' values
86
87 functors::Identity df; // a simple functor that just returns its argument
89
90 trace.beginBlock("image");
91
94 Domain domain(Point(1,1), Point(16,16));
95 Image image(domain);
97
99 unsigned char i = 0;
100 for (Image::Iterator it = image.begin(); it != image.end(); ++it)
101 *it = i++;
103
104 aBoard.clear();
105 Display2DFactory::drawImage<HueShade>(aBoard, image, (unsigned char)0, (unsigned char)255);
106 aBoard.saveSVG("image.svg");
107
108 trace.endBlock();
109
110 trace.beginBlock("subImage");
111
114 Domain subDomain(Point(1,1), Point(8,8));
115 ConstImageAdapterForSubImage subImage(image, subDomain, df, df);
117
118 aBoard.clear();
119 Display2DFactory::drawImage<HueShade>(aBoard, subImage, (unsigned char)0, (unsigned char)255);
120 aBoard.saveSVG("subImage.svg");
121
122 trace.endBlock();
123
124 trace.beginBlock("specificImage");
125
127 DigitalSet set(domain);
128 for( unsigned int y=0; y < 17; y++)
129 for( unsigned int x=0; x < 17; x++)
130 if ((x%2) && (y%2))
131 set.insertNew(Point(x,y));
132
133 DigitalSetDomain<DigitalSet> specificDomain(set);
135
138 ConstImageAdapterForSpecificImage specificImage(image, specificDomain, df, df);
140
141 aBoard.clear();
142 Display2DFactory::drawImage<HueShade>(aBoard, specificImage, (unsigned char)0, (unsigned char)255);
143 aBoard.saveSVG("specificImage.svg");
144
145 trace.endBlock();
146
147 trace.beginBlock("thresholderImage");
148
152 ConstImageAdapterForThresholderImage thresholderImage(image, domain, df, t);
154
155 aBoard.clear();
156 Display2DFactory::drawImage<Gray>(aBoard, thresholderImage, (unsigned char)0, (unsigned char)1);
157 aBoard.saveSVG("thresholderImage.svg");
158
159 trace.endBlock();
160
161 trace.beginBlock("logImage");
162
165 LogScaleFunctor<Image::Value> logScale;
166 ConstImageAdapterForLogScale logImage(image, domain, df, logScale);
168
169 aBoard.clear();
170 Display2DFactory::drawImage<HueShadeDouble>(aBoard, logImage, 0.0, logScale(255));
171 aBoard.saveSVG("logImage.svg");
172
173 trace.endBlock();
174
175 return 0;
176}
177// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Constructs a domain limited to the given digital set.
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
void beginBlock(const std::string &keyword="")
double endBlock()
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
int main()
[LogScaleFunctor]
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
Aim: Define a simple default functor that just returns its argument.
MyPointD Point
Definition: testClone2.cpp:383
Domain domain