DGtal  1.3.beta
testMagickReader.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/images/ImageSelector.h"
36 #include "DGtal/io/colormaps/HueShadeColorMap.h"
37 #include "DGtal/io/readers/MagickReader.h"
38 #include "DGtal/io/boards/Board2D.h"
39 #include "ConfigTest.h"
40 #include "DGtalCatch.h"
42 
43 using namespace std;
44 using namespace DGtal;
45 
47 // Functions for testing class MagickReader.
50 
51 struct Color2Gray{
52  Color2Gray(){}
53  unsigned char operator()(const Color &c) const
54  {
55  return (c.red() + c.green() + c.blue())%256;
56  }
57 };
58 
59 TEST_CASE( "Magick Reader" )
60 {
61  SECTION("Color->grayscale")
62  {
63  //Default image selector = STLVector
65 
66  std::string filename = testPath + "samples/color64.png";
67 
68  trace.info()<<"Importing: "<<filename<<endl;
69 
71  Image img = reader.importImage( filename , Color2Gray());
72 
73  Board2D board;
74  typedef HueShadeColorMap<unsigned char,2> HueTwice;
75 
77  Display2DFactory::drawImage<HueTwice>(board, img, (unsigned char)0, (unsigned char)255);
78  board.saveSVG("testMagick-export.svg");
79 
80  REQUIRE(img.isValid());
81  REQUIRE(img.extent() == Z2i::Vector(64,64));
82  }
83 
84  SECTION("Color->Color")
85  {
86  typedef ImageSelector<Z2i::Domain, Color>::Type ImageColor;
87 
88  std::string filename = testPath + "samples/color64.png";
89 
90  trace.info()<<"Importing: "<<filename<<endl;
91 
93  ImageColor img = reader.importImage( filename );
94 
95  Color a = img( Z2i::Point(1,1));
96  CAPTURE( a );
97  img.setValue( Z2i::Point(1,1), Color(13,13,13));
98  a = img( Z2i::Point(1,1));
99  CAPTURE( a );
100 
101  REQUIRE(img.isValid());
102  REQUIRE(img.extent() == Z2i::Vector(64,64));
103  }
104 }
105 
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
LibBoard::Board::UCentimeter
@ UCentimeter
Definition: Board.h:43
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
DGtal::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: HueShadeColorMap.h:90
DGtal::trace
Trace trace
Definition: Common.h:154
REQUIRE
REQUIRE(domain.isInside(aPoint))
CAPTURE
CAPTURE(thicknessHV)
DGtal::Trace::info
std::ostream & info()
DGtal::MagickReader
Aim: implements methods to read a 2D image using the ImageMagick library.
Definition: MagickReader.h:111
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal::MagickReader::importImage
static ImageContainer importImage(const std::string &filename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
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
DGtal::PointVector< dim, Integer >
SECTION
SECTION("Testing constant forward iterators")
Definition: testSimpleRandomAccessRangeFromPoint.cpp:66
TEST_CASE
TEST_CASE("Magick Reader")
Definition: testMagickReader.cpp:59