Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
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.ppm";
24  int blockRadius = 150;
25  int bins = 256;
26  float slope = 3.0f;
27  unsigned int size = 11;
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]) == "--size" && i + 1 < argc) {
40  size = (unsigned int)atoi(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>] [--bins <nb "
47  "histogram bins for CLAHE>] [--slope <slope for CLAHE>]"
48  " [--size <Gaussian kernel size>] [--weight <unsharp mask "
49  "weighting>]"
50  " [--help]"
51  << std::endl;
52  return EXIT_SUCCESS;
53  }
54  }
55 
57  vpImage<vpRGBa> I_color;
58  vpImageIo::read(I_color, input_filename);
60 
61 #ifdef VISP_HAVE_X11
62  vpDisplayX d, d2, d3, d4, d5, d6;
63 #elif defined(VISP_HAVE_GDI)
64  vpDisplayGDI d, d2, d3, d4, d5, d6;
65 #elif defined(VISP_HAVE_OPENCV)
66  vpDisplayOpenCV d, d2, d3, d4, d5, d6;
67 #endif
68  d.init(I_color, 0, 0, "Input color image");
69 
71  vpImage<vpRGBa> I_stretch;
72  vp::stretchContrast(I_color, I_stretch);
74  d2.init(I_stretch, I_color.getWidth(), 10, "Stretch contrast");
75 
77  vpImage<vpRGBa> I_stretch_hsv;
78  vp::stretchContrastHSV(I_color, I_stretch_hsv);
80  d3.init(I_stretch_hsv, 0, I_color.getHeight() + 80, "Stretch contrast HSV");
81 
83  vpImage<vpRGBa> I_hist_eq;
84  vp::equalizeHistogram(I_color, I_hist_eq);
86  d4.init(I_hist_eq, I_color.getWidth(), I_color.getHeight() + 80, "Histogram equalization");
87 
89  vpImage<vpRGBa> I_clahe;
90  vp::clahe(I_color, I_clahe, blockRadius, bins, slope);
92  d5.init(I_clahe, 0, 2 * I_color.getHeight() + 80, "Histogram equalization");
93 
95  vpImage<vpRGBa> I_unsharp;
96  vp::unsharpMask(I_clahe, I_unsharp, size, weight);
98  d6.init(I_unsharp, I_color.getWidth(), 2 * I_color.getHeight() + 80, "Unsharp mask");
99 
100  vpDisplay::display(I_color);
101  vpDisplay::display(I_stretch);
102  vpDisplay::display(I_stretch_hsv);
103  vpDisplay::display(I_hist_eq);
104  vpDisplay::display(I_clahe);
105  vpDisplay::display(I_unsharp);
106  vpDisplay::displayText(I_unsharp, 20, 20, "Click to quit.", vpColor::red);
107  vpDisplay::flush(I_color);
108  vpDisplay::flush(I_stretch);
109  vpDisplay::flush(I_stretch_hsv);
110  vpDisplay::flush(I_hist_eq);
111  vpDisplay::flush(I_clahe);
112  vpDisplay::flush(I_unsharp);
113  vpDisplay::getClick(I_unsharp);
114 
115  return EXIT_SUCCESS;
116 #else
117  (void)argc;
118  (void)argv;
119  return 0;
120 #endif
121 }
VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, const unsigned int size=7, const double weight=0.6)
Definition: vpImgproc.cpp:624
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
Definition: vpImage.h:239
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
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:151
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:180
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
Definition: vpImgproc.cpp:418
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
Definition: vpImgproc.cpp:555
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, const int blockRadius=150, const int bins=256, const float slope=3.0f, const bool fast=true)
Definition: vpCLAHE.cpp:228
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:207
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
Definition: vpImgproc.cpp:164
unsigned int getHeight() const
Definition: vpImage.h:178