Visual Servoing Platform  version 3.6.1 under development (2024-04-24)
testImageAddSub.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Test image addition / subtraction.
33  *
34 *****************************************************************************/
35 
36 #include <visp3/core/vpConfig.h>
37 
44 #if defined(VISP_HAVE_CATCH2)
45 #define CATCH_CONFIG_RUNNER
46 #include "common.hpp"
47 #include <catch.hpp>
48 #include <visp3/core/vpImageTools.h>
49 #include <visp3/core/vpIoTools.h>
50 #include <visp3/io/vpImageIo.h>
51 
52 TEST_CASE("Test vpImageTools::imageAdd()", "[image_add]")
53 {
54  const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "Klimt/Klimt.pgm");
56  vpImageIo::read(I, filepath);
57 
58  SECTION("I + Inull = I")
59  {
60  vpImage<unsigned char> Inull(I.getHeight(), I.getWidth(), 0);
62  vpImageTools::imageAdd(I, Inull, Iadd);
63  CHECK((Iadd == I));
64  }
65 
66  SECTION("I + I without saturation")
67  {
68  const bool saturation = false;
70  common_tools::imageAddRef(I, I, Iref, saturation);
71 
73  vpImageTools::imageAdd(I, I, Iadd, saturation);
74  CHECK((Iadd == Iref));
75  }
76 
77  SECTION("I + I with saturation")
78  {
79  const bool saturation = true;
81  common_tools::imageAddRef(I, I, Iref, saturation);
82 
84  vpImageTools::imageAdd(I, I, Iadd, saturation);
85  CHECK((Iadd == Iref));
86  }
87 }
88 
89 TEST_CASE("Test vpImageTools::imageDifference()", "[image_difference]")
90 {
91  const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "Klimt/Klimt.pgm");
93  vpImageIo::read(I, filepath);
94 
95  SECTION("I - Inull = I")
96  {
97  vpImage<unsigned char> Inull(I.getHeight(), I.getWidth(), 0);
99  vpImageTools::imageSubtract(I, Inull, Isub);
100  CHECK((Isub == I));
101  }
102 
103  SECTION("I - I2 without saturation")
104  {
105  const bool saturation = false;
108  common_tools::fill(I2);
109 
110  common_tools::imageSubtractRef(I, I2, Iref, saturation);
111 
113  vpImageTools::imageSubtract(I, I2, Isub, saturation);
114  CHECK((Isub == Iref));
115  }
116 
117  SECTION("I - I2 with saturation ")
118  {
119  const bool saturation = true;
122  common_tools::fill(I2);
123 
124  common_tools::imageSubtractRef(I, I2, Iref, saturation);
125 
127  vpImageTools::imageSubtract(I, I2, Isub, saturation);
128  CHECK((Isub == Iref));
129  }
130 }
131 
132 int main(int argc, char *argv[])
133 {
134  Catch::Session session; // There must be exactly one instance
135 
136  // Let Catch (using Clara) parse the command line
137  session.applyCommandLine(argc, argv);
138 
139  int numFailed = session.run();
140 
141  // numFailed is clamped to 255 as some unices only use the lower 8 bits.
142  // This clamping has already been applied, so just return it here
143  // You can also do any post run clean-up here
144  return numFailed;
145 }
146 #else
147 int main() { return EXIT_SUCCESS; }
148 #endif
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:143
static void imageSubtract(const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Ires, bool saturate=false)
static void imageAdd(const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Ires, bool saturate=false)
unsigned int getWidth() const
Definition: vpImage.h:245
unsigned int getHeight() const
Definition: vpImage.h:184
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1832
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:2195