Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
catchImageAddSub.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Test image addition / subtraction.
32 */
33
34#include <visp3/core/vpConfig.h>
35
41
42#if defined(VISP_HAVE_CATCH2)
43
44#include "common.hpp"
45#include <catch_amalgamated.hpp>
46#include <visp3/core/vpImageTools.h>
47#include <visp3/core/vpIoTools.h>
48#include <visp3/io/vpImageIo.h>
49
50#ifdef ENABLE_VISP_NAMESPACE
51using namespace VISP_NAMESPACE_NAME;
52#endif
53
54TEST_CASE("Test vpImageTools::imageAdd()", "[image_add]")
55{
56 const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "Klimt/Klimt.pgm");
58 vpImageIo::read(I, filepath);
59
60 SECTION("I + Inull = I")
61 {
62 vpImage<unsigned char> Inull(I.getHeight(), I.getWidth(), 0);
64 vpImageTools::imageAdd(I, Inull, Iadd);
65 CHECK((Iadd == I));
66 }
67
68 SECTION("I + I without saturation")
69 {
70 const bool saturation = false;
72 common_tools::imageAddRef(I, I, Iref, saturation);
73
75 vpImageTools::imageAdd(I, I, Iadd, saturation);
76 CHECK((Iadd == Iref));
77 }
78
79 SECTION("I + I with saturation")
80 {
81 const bool saturation = true;
83 common_tools::imageAddRef(I, I, Iref, saturation);
84
86 vpImageTools::imageAdd(I, I, Iadd, saturation);
87 CHECK((Iadd == Iref));
88 }
89}
90
91TEST_CASE("Test vpImageTools::imageDifference()", "[image_difference]")
92{
93 const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "Klimt/Klimt.pgm");
95 vpImageIo::read(I, filepath);
96
97 SECTION("I - Inull = I")
98 {
99 vpImage<unsigned char> Inull(I.getHeight(), I.getWidth(), 0);
101 vpImageTools::imageSubtract(I, Inull, Isub);
102 CHECK((Isub == I));
103 }
104
105 SECTION("I - I2 without saturation")
106 {
107 const bool saturation = false;
109 vpImage<unsigned char> I2(I.getHeight(), I.getWidth());
110 common_tools::fill(I2);
111
112 common_tools::imageSubtractRef(I, I2, Iref, saturation);
113
115 vpImageTools::imageSubtract(I, I2, Isub, saturation);
116 CHECK((Isub == Iref));
117 }
118
119 SECTION("I - I2 with saturation ")
120 {
121 const bool saturation = true;
123 vpImage<unsigned char> I2(I.getHeight(), I.getWidth());
124 common_tools::fill(I2);
125
126 common_tools::imageSubtractRef(I, I2, Iref, saturation);
127
129 vpImageTools::imageSubtract(I, I2, Isub, saturation);
130 CHECK((Isub == Iref));
131 }
132}
133
134int main(int argc, char *argv[])
135{
136 Catch::Session session;
137 session.applyCommandLine(argc, argv);
138 int numFailed = session.run();
139 return numFailed;
140}
141#else
142int main() { return EXIT_SUCCESS; }
143#endif
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
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)
Definition of the vpImage class member functions.
Definition vpImage.h:131
static std::string getViSPImagesDataPath()
static std::string createFilePath(const std::string &parent, const std::string &child)