Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
tutorial-contrast-sharpening.cpp
1 
3 #include <cstdlib>
4 #include <iostream>
5 #include <visp3/core/vpImage.h>
6 #include <visp3/gui/vpDisplayGDI.h>
7 #include <visp3/gui/vpDisplayOpenCV.h>
8 #include <visp3/gui/vpDisplayX.h>
9 #include <visp3/io/vpImageIo.h>
10 
11 #if defined(VISP_HAVE_MODULE_IMGPROC)
12 #include <visp3/imgproc/vpImgproc.h>
15 #endif
16 
17 int main(int argc, const char **argv)
18 {
20 #if defined(VISP_HAVE_MODULE_IMGPROC) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
21  std::string input_filename = "Crayfish-low-contrast.png";
24  int blockRadius = 150;
25  int bins = 256;
26  float slope = 3.0f;
27  float sigma = 2.0f;
28  double weight = 0.5;
29 
30  for (int i = 1; i < argc; i++) {
31  if (std::string(argv[i]) == "--input" && i + 1 < argc) {
32  input_filename = std::string(argv[i + 1]);
33  } else if (std::string(argv[i]) == "--blockRadius" && i + 1 < argc) {
34  blockRadius = atoi(argv[i + 1]);
35  } else if (std::string(argv[i]) == "--bins" && i + 1 < argc) {
36  bins = atoi(argv[i + 1]);
37  } else if (std::string(argv[i]) == "--slope" && i + 1 < argc) {
38  slope = (float)atof(argv[i + 1]);
39  } else if (std::string(argv[i]) == "--sigma" && i + 1 < argc) {
40  sigma = (float)atof(argv[i + 1]);
41  } else if (std::string(argv[i]) == "--weight" && i + 1 < argc) {
42  weight = atof(argv[i + 1]);
43  } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
44  std::cout << "Usage: " << argv[0]
45  << " [--input <input image>]"
46  " [--blockRadius <block radius for CLAHE>] "
47  " [--bins <nb histogram bins for CLAHE>] [--slope <slope for CLAHE>]"
48  " [--sigma <Gaussian kernel standard deviation>] [--weight <unsharp mask weighting>]"
49  " [--help] [-h]"
50  << std::endl;
51  return EXIT_SUCCESS;
52  }
53  }
54 
56  vpImage<vpRGBa> I_color;
57  vpImageIo::read(I_color, input_filename);
59 
60 #ifdef VISP_HAVE_X11
61  vpDisplayX d, d2, d3, d4, d5, d6;
62 #elif defined(VISP_HAVE_GDI)
63  vpDisplayGDI d, d2, d3, d4, d5, d6;
64 #elif defined(VISP_HAVE_OPENCV)
65  vpDisplayOpenCV d, d2, d3, d4, d5, d6;
66 #endif
67  d.init(I_color, 0, 0, "Input color image");
68 
70  vpImage<vpRGBa> I_stretch;
71  vp::stretchContrast(I_color, I_stretch);
73  d2.init(I_stretch, I_color.getWidth(), 10, "Stretch contrast");
74 
76  vpImage<vpRGBa> I_stretch_hsv;
77  vp::stretchContrastHSV(I_color, I_stretch_hsv);
79  d3.init(I_stretch_hsv, 0, I_color.getHeight() + 80, "Stretch contrast HSV");
80 
82  vpImage<vpRGBa> I_hist_eq;
83  vp::equalizeHistogram(I_color, I_hist_eq);
85  d4.init(I_hist_eq, I_color.getWidth(), I_color.getHeight() + 80, "Histogram equalization");
86 
88  vpImage<vpRGBa> I_clahe;
89  vp::clahe(I_color, I_clahe, blockRadius, bins, slope);
91  d5.init(I_clahe, 0, 2 * I_color.getHeight() + 80, "CLAHE");
92 
94  vpImage<vpRGBa> I_unsharp;
95  vp::unsharpMask(I_clahe, I_unsharp, sigma, weight);
97  d6.init(I_unsharp, I_color.getWidth(), 2 * I_color.getHeight() + 80, "Unsharp mask");
98 
99  vpDisplay::display(I_color);
100  vpDisplay::display(I_stretch);
101  vpDisplay::display(I_stretch_hsv);
102  vpDisplay::display(I_hist_eq);
103  vpDisplay::display(I_clahe);
104  vpDisplay::display(I_unsharp);
105  vpDisplay::displayText(I_unsharp, 20, 20, "Click to quit.", vpColor::red);
106  vpDisplay::flush(I_color);
107  vpDisplay::flush(I_stretch);
108  vpDisplay::flush(I_stretch_hsv);
109  vpDisplay::flush(I_hist_eq);
110  vpDisplay::flush(I_clahe);
111  vpDisplay::flush(I_unsharp);
112  vpDisplay::getClick(I_unsharp);
113 
114  return EXIT_SUCCESS;
115 #else
116  (void)argc;
117  (void)argv;
118  return 0;
119 #endif
120 }
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:149
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:134
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:217
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
Definition: vpImgproc.cpp:419
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
Definition: vpImgproc.cpp:556
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
VISP_EXPORT void clahe(const vpImage< unsigned char > &I1, vpImage< unsigned char > &I2, int blockRadius=150, int bins=256, float slope=3.0f, bool fast=true)
Definition: vpCLAHE.cpp:228
unsigned int getHeight() const
Definition: vpImage.h:188
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
Definition: vpImgproc.cpp:165
vp_deprecated VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, unsigned int size=7, double weight=0.6)
Definition: vpImgproc.cpp:719
unsigned int getWidth() const
Definition: vpImage.h:246