Visual Servoing Platform  version 3.6.1 under development (2024-06-15)
vpImgproc.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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  * Static functions for basic image processing functions.
32  */
33 
40 #ifndef _vpImgproc_h_
41 #define _vpImgproc_h_
42 
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpImage.h>
45 #include <visp3/core/vpImageMorphology.h>
46 #include <visp3/imgproc/vpContours.h>
47 
48 namespace VISP_NAMESPACE_NAME
49 {
50 
51 #define USE_OLD_FILL_HOLE 0
52 
58 {
61  RETINEX_HIGH = 2
62 };
63 
67 typedef enum
68 {
95 
99 typedef enum vpGammaMethod
100 {
102  GAMMA_LOG_BASED = 1,
107  GAMMA_CDF_BASED = 3,
117 
126 VISP_EXPORT std::string vpGammaMethodList(const std::string &pref = "<", const std::string &sep = " , ",
127  const std::string &suf = ">");
128 
135 VISP_EXPORT std::string vpGammaMethodToString(const vpGammaMethod &type);
136 
143 VISP_EXPORT vpGammaMethod vpGammaMethodFromString(const std::string &name);
144 
149 {
150  GAMMA_RGB = 0,
151  GAMMA_HSV = 1,
155 
164 VISP_EXPORT std::string vpGammaColorHandlingList(const std::string &pref = "<", const std::string &sep = " , ",
165  const std::string &suf = ">");
166 
173 VISP_EXPORT std::string vpGammaColorHandlingToString(const vpGammaColorHandling &type);
174 
181 VISP_EXPORT vpGammaColorHandling vpGammaColorHandlingFromString(const std::string &name);
182 
193 VISP_EXPORT void adjust(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, double alpha, double beta);
194 
206 VISP_EXPORT void adjust(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I1, VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I2, double alpha, double beta);
207 
218 VISP_EXPORT void adjust(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, const double alpha, double beta);
219 
231 VISP_EXPORT void adjust(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2, double alpha, double beta);
232 
262 VISP_EXPORT void clahe(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I1, VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I2, int blockRadius = 150,
263  int bins = 256, float slope = 3.0f, bool fast = true);
264 
292 VISP_EXPORT void clahe(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2, int blockRadius = 150, int bins = 256,
293  float slope = 3.0f, bool fast = true);
294 
305 VISP_EXPORT void equalizeHistogram(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, const VISP_NAMESPACE_ADDRESSING vpImage<bool> *p_mask = nullptr);
306 
318 VISP_EXPORT void equalizeHistogram(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I1, VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I2,
319  const VISP_NAMESPACE_ADDRESSING vpImage<bool> *p_mask = nullptr);
320 
334 VISP_EXPORT void equalizeHistogram(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, bool useHSV = false);
335 
350 VISP_EXPORT void equalizeHistogram(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2, bool useHSV = false);
351 
367 VISP_EXPORT void gammaCorrection(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, const float &gamma, const vpGammaMethod &method = GAMMA_MANUAL,
368  const VISP_NAMESPACE_ADDRESSING vpImage<bool> *p_mask = nullptr);
369 
386 VISP_EXPORT void gammaCorrection(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I1, VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I2, const float &gamma,
387  const vpGammaMethod &method = GAMMA_MANUAL, const VISP_NAMESPACE_ADDRESSING vpImage<bool> *p_mask = nullptr);
388 
402 VISP_EXPORT void gammaCorrection(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, const float &gamma, const vpGammaColorHandling &colorHandling = GAMMA_RGB,
403  const vpGammaMethod &method = GAMMA_MANUAL, const VISP_NAMESPACE_ADDRESSING vpImage<bool> *p_mask = nullptr);
404 
419 VISP_EXPORT void gammaCorrection(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2, const float &gamma,
420  const vpGammaColorHandling &colorHandling = GAMMA_RGB,
421  const vpGammaMethod &method = GAMMA_MANUAL, const VISP_NAMESPACE_ADDRESSING vpImage<bool> *p_mask = nullptr);
422 
444 VISP_EXPORT void retinex(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, int scale = 240, int scaleDiv = 3, int level = RETINEX_UNIFORM,
445  double dynamic = 1.2, int kernelSize = -1);
446 
469 VISP_EXPORT void retinex(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2, int scale = 240, int scaleDiv = 3,
470  int level = RETINEX_UNIFORM, double dynamic = 1.2, int kernelSize = -1);
471 
479 VISP_EXPORT void stretchContrast(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I);
480 
489 VISP_EXPORT void stretchContrast(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I1, VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I2);
490 
498 VISP_EXPORT void stretchContrast(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I);
499 
508 VISP_EXPORT void stretchContrast(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2);
509 
518 VISP_EXPORT void stretchContrastHSV(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I);
519 
529 VISP_EXPORT void stretchContrastHSV(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I1, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I2);
530 
540 VISP_EXPORT void unsharpMask(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, float sigma, double weight = 0.6);
541 
552 VISP_EXPORT void unsharpMask(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &Ires, float sigma,
553  double weight = 0.6);
554 
564 VISP_EXPORT void unsharpMask(VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, float sigma, double weight = 0.6);
565 
576 VISP_EXPORT void unsharpMask(const VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &I, VISP_NAMESPACE_ADDRESSING vpImage<VISP_NAMESPACE_ADDRESSING vpRGBa> &Ires, float sigma, double weight = 0.6);
577 
588 VISP_EXPORT void connectedComponents(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, VISP_NAMESPACE_ADDRESSING vpImage<int> &labels, int &nbComponents,
589  const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity = VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4);
590 
598 VISP_EXPORT void fillHoles(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I
599 #if USE_OLD_FILL_HOLE
600  ,
601  const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity = VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4
602 #endif
603 );
604 
616 VISP_EXPORT void floodFill(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, const VISP_NAMESPACE_ADDRESSING vpImagePoint &seedPoint, const unsigned char oldValue,
617  const unsigned char newValue,
618  const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity = VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4);
619 
638 VISP_EXPORT void reconstruct(const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &marker, const VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &mask,
639  VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &h_kp1 /*alias I */,
640  const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity = VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4);
641 
652 VISP_EXPORT unsigned char autoThreshold(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, const vpAutoThresholdMethod &method,
653  const unsigned char backgroundValue = 0,
654  const unsigned char foregroundValue = 255);
655 
656 } // namespace
657 
658 #endif
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
VISP_EXPORT void adjust(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, double alpha, double beta)
VISP_EXPORT void clahe(const VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I1, VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I2, int blockRadius=150, int bins=256, float slope=3.0f, bool fast=true)
VISP_EXPORT void floodFill(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const VISP_NAMESPACE_ADDRESSING vpImagePoint &seedPoint, const unsigned char oldValue, const unsigned char newValue, const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity=VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4)
VISP_EXPORT void connectedComponents(const VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, VISP_NAMESPACE_ADDRESSING vpImage< int > &labels, int &nbComponents, const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity=VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4)
VISP_EXPORT void stretchContrast(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I)
VISP_EXPORT void stretchContrastHSV(VISP_NAMESPACE_ADDRESSING vpImage< VISP_NAMESPACE_ADDRESSING vpRGBa > &I)
VISP_EXPORT void gammaCorrection(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const float &gamma, const vpGammaMethod &method=GAMMA_MANUAL, const VISP_NAMESPACE_ADDRESSING vpImage< bool > *p_mask=nullptr)
VISP_EXPORT void equalizeHistogram(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const VISP_NAMESPACE_ADDRESSING vpImage< bool > *p_mask=nullptr)
VISP_EXPORT void fillHoles(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I)
VISP_EXPORT void reconstruct(const VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &marker, const VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &mask, VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &h_kp1, const VISP_NAMESPACE_ADDRESSING vpImageMorphology::vpConnexityType &connexity=VISP_NAMESPACE_ADDRESSING vpImageMorphology::CONNEXITY_4)
VISP_EXPORT void retinex(VISP_NAMESPACE_ADDRESSING vpImage< VISP_NAMESPACE_ADDRESSING vpRGBa > &I, int scale=240, int scaleDiv=3, int level=RETINEX_UNIFORM, double dynamic=1.2, int kernelSize=-1)
VISP_EXPORT void unsharpMask(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, float sigma, double weight=0.6)
VISP_EXPORT unsigned char autoThreshold(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const vpAutoThresholdMethod &method, const unsigned char backgroundValue=0, const unsigned char foregroundValue=255)
VISP_EXPORT vpGammaMethod vpGammaMethodFromString(const std::string &name)
Cast a string into a vpGammaMethod.
Definition: vpImgproc.cpp:116
VISP_EXPORT vpGammaColorHandling vpGammaColorHandlingFromString(const std::string &name)
Cast a string into a vpGammaColorHandling.
Definition: vpImgproc.cpp:164
vpGammaColorHandling
How to handle color images when applying Gamma Correction.
Definition: vpImgproc.h:149
VISP_EXPORT std::string vpGammaColorHandlingToString(const vpGammaColorHandling &type)
Cast a vpGammaColorHandling into a string, to know its name.
Definition: vpImgproc.cpp:147
VISP_EXPORT std::string vpGammaMethodList(const std::string &pref="<", const std::string &sep=" , ", const std::string &suf=">")
Get the list of available vpGammaMethod.
Definition: vpImgproc.cpp:73
VISP_EXPORT std::string vpGammaColorHandlingList(const std::string &pref="<", const std::string &sep=" , ", const std::string &suf=">")
Get the list of available vpGammaColorHandling.
Definition: vpImgproc.cpp:133
@ RETINEX_HIGH
Enhances the bright regions of the image.
Definition: vpImgproc.h:61
@ RETINEX_LOW
Enhances dark regions of the image.
Definition: vpImgproc.h:60
@ RETINEX_UNIFORM
Tends to treat all image intensities similarly.
Definition: vpImgproc.h:59
vpGammaMethod
Gamma Correction automatic methods.
Definition: vpImgproc.h:100
VISP_EXPORT std::string vpGammaMethodToString(const vpGammaMethod &type)
Cast a vpGammaMethod into a string, to know its name.
Definition: vpImgproc.cpp:87