DGtal  1.5.beta
testSTBWriter.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtalCatch.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/io/readers/STBReader.h"
37 #include "DGtal/io/writers/STBWriter.h"
38 #include "DGtal/images/ImageSelector.h"
39 
40 #include "DGtal/io/colormaps/GradientColorMap.h"
41 #include "DGtal/io/writers/PPMWriter.h"
43 
44 using namespace std;
45 using namespace DGtal;
46 
48 // Functions for testing class STBReader.
50 
51 TEST_CASE( "Testing STBWriter" )
52 {
53  SECTION("Testing feature io/readers of STBWriter (Grayscale PNG)")
54  {
55  std::string filename = testPath + "samples/contourS.png";
57  Image image = STBReader<Image>::import( filename );
58  CAPTURE(image);
59  PPMWriter<Image>::exportPPM("contourS-export.ppm", image);
60 
61  STBWriter<Image>::exportPNG("contourS-export.png", image);
62  CHECK( image.isValid());
63  }
64 
65  SECTION("Testing feature io/readers of STBWriter (PNG)")
66  {
67  std::string filename = testPath + "samples/color64.png";
69  Image image = STBReader<Image>::import( filename );
70  CHECK( image.isValid());
71  PPMWriter<Image>::exportPPM("color64-export.ppm", image);
72  STBWriter<Image>::exportTGA("color64-export.tga", image);
73  STBWriter<Image>::exportJPG("color64-export.jpg", image);
74  STBWriter<Image>::exportBMP("color64-export.bmp", image);
75  }
76 
77  SECTION("Testing scalar functor (PNG)")
78  {
81 
82  image.setValue(Z2i::Point(3,3), 10);
83  image.setValue(Z2i::Point(1,1), 1);
84  image.setValue(Z2i::Point(7,7), 20);
85 
86  // Creating colormap.
87  GradientColorMap<int> cmap_grad( 0, 30 );
88  cmap_grad.addColor( Color( 50, 50, 255 ) );
89  cmap_grad.addColor( Color( 255, 0, 0 ) );
90  cmap_grad.addColor( Color( 255, 255, 10 ) );
91 
92  CHECK( image.isValid());
93  STBWriter<Image,GradientColorMap<int>>::exportPNG("scalar-export.jpg", image, cmap_grad );
94  }
95 
96 }
97 
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: Image reader using the stb_image.h header only code.
Definition: STBReader.h:62
Aim: Image Writer using the stb_image.h header only code.
Definition: STBWriter.h:65
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Export a 2D and a 3D Image using the Netpbm PPM formats (ASCII mode).
Definition: PPMWriter.h:73
CAPTURE(thicknessHV)
TEST_CASE("Testing STBWriter")
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image
SECTION("Testing constant forward iterators")