Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-brightness-adjustment.cpp
1
2
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)
13#include <visp3/imgproc/vpImgproc.h>
15#endif
16
17int main(int argc, const char **argv)
18{
20#if defined(VISP_HAVE_MODULE_IMGPROC) && \
21 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) && \
22 (defined(VISP_HAVE_PNG) || defined(VISP_HAVE_OPENCV))
25 std::string input_filename = "Sample_low_brightness.png";
26 double alpha = 10.0, beta = 50.0;
27 double gamma = 3.5;
28 int scale = 240, scaleDiv = 3, level = 0, kernelSize = -1;
29 double dynamic = 3.0;
30
31 for (int i = 1; i < argc; i++) {
32 if (std::string(argv[i]) == "--input" && i + 1 < argc) {
33 input_filename = std::string(argv[i + 1]);
34 } else if (std::string(argv[i]) == "--alpha" && i + 1 < argc) {
35 alpha = atof(argv[i + 1]);
36 } else if (std::string(argv[i]) == "--beta" && i + 1 < argc) {
37 beta = atof(argv[i + 1]);
38 } else if (std::string(argv[i]) == "--gamma" && i + 1 < argc) {
39 gamma = atof(argv[i + 1]);
40 } else if (std::string(argv[i]) == "--scale" && i + 1 < argc) {
41 scale = atoi(argv[i + 1]);
42 } else if (std::string(argv[i]) == "--scaleDiv" && i + 1 < argc) {
43 scaleDiv = atoi(argv[i + 1]);
44 } else if (std::string(argv[i]) == "--level" && i + 1 < argc) {
45 level = atoi(argv[i + 1]);
46 } else if (std::string(argv[i]) == "--kernelSize" && i + 1 < argc) {
47 kernelSize = atoi(argv[i + 1]);
48 } else if (std::string(argv[i]) == "--dynamic" && i + 1 < argc) {
49 dynamic = atof(argv[i + 1]);
50 } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
51 std::cout << "Usage: " << argv[0]
52 << " [--input <input image>]"
53 " [--alpha <alpha for vp::adjust()>] [--beta <beta for "
54 "vp::adjust()>]"
55 " [--gamma <gamma for vp::gammaCorrection()>]"
56 " [--scale <scale for vp::retinex()> [--scaleDiv for "
57 "vp::retinex()]"
58 " [--level <level for vp::retinex()> [--kernelSize "
59 "<kernelSize for vp::retinex()>]"
60 " [--dynamic <dynamic for vp::retinex()>] [--help]"
61 << std::endl;
62 return EXIT_SUCCESS;
63 }
64 }
65
66 vpImage<vpRGBa> I_color;
67 vpImageIo::read(I_color, input_filename);
68
69 vpImage<vpRGBa> I_color_res(I_color.getHeight(), 2 * I_color.getWidth());
70 I_color_res.insert(I_color, vpImagePoint());
71#ifdef VISP_HAVE_X11
72 vpDisplayX d(I_color_res);
73#elif defined(VISP_HAVE_GDI)
74 vpDisplayGDI d(I_color_res);
75#elif defined(HAVE_OPENCV_HIGHGUI)
76 vpDisplayOpenCV d(I_color_res);
77#endif
78
80 vpImage<vpRGBa> I_color_adjust;
81 vp::adjust(I_color, I_color_adjust, alpha, beta);
83 I_color_res.insert(I_color_adjust, vpImagePoint(0, I_color.getWidth()));
84 std::stringstream ss;
85 ss << "Sample_low_brightness_alpha=" << alpha << "_beta=" << beta << ".png";
86 vpImageIo::write(I_color_res, ss.str());
87
88 vpDisplay::display(I_color_res);
89 vpDisplay::displayText(I_color_res, 20, 20, "Brightness and contrast adjustment. Click to continue.", vpColor::red);
90 vpDisplay::flush(I_color_res);
91 vpDisplay::getClick(I_color_res);
92
94 vpImage<vpRGBa> I_color_gamma_correction;
95 vp::gammaCorrection(I_color, I_color_gamma_correction, gamma);
97 I_color_res.insert(I_color_gamma_correction, vpImagePoint(0, I_color.getWidth()));
98 ss.str("");
99 ss << "Sample_low_brightness_gamma=" << gamma << ".png";
100 vpImageIo::write(I_color_res, ss.str());
101
102 vpDisplay::display(I_color_res);
103 vpDisplay::displayText(I_color_res, 20, 20, "Gamma correction. Click to continue.", vpColor::red);
104 vpDisplay::flush(I_color_res);
105 vpDisplay::getClick(I_color_res);
106
108 vpImage<vpRGBa> I_color_equalize_histogram;
109 vp::equalizeHistogram(I_color, I_color_equalize_histogram);
111 I_color_res.insert(I_color_equalize_histogram, vpImagePoint(0, I_color.getWidth()));
112 ss.str("");
113 ss << "Sample_low_brightness_eqHist.png";
114 vpImageIo::write(I_color_res, ss.str());
115
116 vpDisplay::display(I_color_res);
117 vpDisplay::displayText(I_color_res, 20, 20, "Histogram equalization. Click to continue.", vpColor::red);
118 vpDisplay::flush(I_color_res);
119 vpDisplay::getClick(I_color_res);
120
122 vpImage<vpRGBa> I_color_retinex;
123 vp::retinex(I_color, I_color_retinex, scale, scaleDiv, level, dynamic, kernelSize);
125 I_color_res.insert(I_color_retinex, vpImagePoint(0, I_color.getWidth()));
126
127 ss.str("");
128 ss << "Sample_low_brightness_scale=" << scale << "_scaleDiv=" << scaleDiv << "_level=" << level
129 << "_dynamic=" << dynamic << "_kernelSize=" << kernelSize << ".png";
130 vpImageIo::write(I_color_res, ss.str());
131
132 vpDisplay::display(I_color_res);
133 vpDisplay::displayText(I_color_res, 20, 20, "Retinex. Click to quit.", vpColor::red);
134 vpDisplay::flush(I_color_res);
135 vpDisplay::getClick(I_color_res);
136#else
137 (void)argc;
138 (void)argv;
139#endif
140 return EXIT_SUCCESS;
141}
static const vpColor red
Definition vpColor.h:211
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
VISP_EXPORT void adjust(vpImage< unsigned char > &I, double alpha, double beta)
Definition vpImgproc.cpp:68
VISP_EXPORT void gammaCorrection(vpImage< unsigned char > &I, double gamma)
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
VISP_EXPORT void retinex(vpImage< vpRGBa > &I, int scale=240, int scaleDiv=3, int level=RETINEX_UNIFORM, double dynamic=1.2, int kernelSize=-1)