5 #include <visp3/core/vpConfig.h>
6 #include <visp3/core/vpImage.h>
7 #include <visp3/core/vpIoTools.h>
8 #include <visp3/gui/vpDisplayFactory.h>
9 #include <visp3/io/vpImageIo.h>
11 #if defined(VISP_HAVE_MODULE_IMGPROC)
13 #include <visp3/imgproc/vpImgproc.h>
17 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
21 #ifdef ENABLE_VISP_NAMESPACE
25 #if defined(VISP_HAVE_MODULE_IMGPROC) && defined(VISP_HAVE_DISPLAY) && \
26 (defined(VISP_HAVE_PNG) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_STBIMAGE) || defined(VISP_HAVE_SIMDLIB)) && \
27 ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
32 const std::string &title,
const std::string &filename_color,
const std::string &filename_gray,
33 const std::string &title_2 =
"")
47 if (!title_2.empty()) {
57 int main(
int argc,
const char **argv)
60 #if defined(VISP_HAVE_MODULE_IMGPROC) && defined(VISP_HAVE_DISPLAY) && \
61 (defined(VISP_HAVE_PNG) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_STBIMAGE) || defined(VISP_HAVE_SIMDLIB)) && \
62 ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
65 std::string input_filename =
"Sample_low_brightness.png";
66 double alpha = 10.0, beta = 50.0;
70 int scale = 240, scaleDiv = 3, level = 0, kernelSize = -1;
72 int scale_display = 2;
74 for (
int i = 1; i < argc; i++) {
75 if (std::string(argv[i]) ==
"--input" && i + 1 < argc) {
77 input_filename = std::string(argv[i]);
79 else if (std::string(argv[i]) ==
"--alpha" && i + 1 < argc) {
81 alpha = atof(argv[i]);
83 else if (std::string(argv[i]) ==
"--beta" && i + 1 < argc) {
87 else if (std::string(argv[i]) ==
"--gamma" && i + 1 < argc) {
89 gamma = atof(argv[i]);
91 else if ((std::string(argv[i]) ==
"--gamma-color-handling") && ((i + 1) < argc)) {
95 else if ((std::string(argv[i]) ==
"--gamma-method") && ((i + 1) < argc)) {
99 else if (std::string(argv[i]) ==
"--scale" && i + 1 < argc) {
101 scale = atoi(argv[i]);
103 else if (std::string(argv[i]) ==
"--scaleDiv" && i + 1 < argc) {
105 scaleDiv = atoi(argv[i]);
107 else if (std::string(argv[i]) ==
"--level" && i + 1 < argc) {
109 level = atoi(argv[i]);
111 else if (std::string(argv[i]) ==
"--kernelSize" && i + 1 < argc) {
113 kernelSize = atoi(argv[i]);
115 else if (std::string(argv[i]) ==
"--dynamic" && i + 1 < argc) {
117 dynamic = atof(argv[i]);
119 else if (std::string(argv[i]) ==
"--scale-display" && i + 1 < argc) {
121 scale_display = atoi(argv[i]);
123 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
124 std::cout <<
"Usage: " << argv[0]
125 <<
" [--input <input image>]"
126 " [--alpha <alpha for adjust()>] [--beta <beta for adjust()>]"
127 " [--gamma <gamma for gammaCorrection()>]"
130 " [--scale <scale for retinex()> [--scaleDiv for retinex()]"
131 " [--level <level for retinex()> [--kernelSize <kernelSize for retinex()>]"
132 " [--dynamic <dynamic for retinex()>] "
133 " [--scale-display <display downscaling factor>] "
162 d->
init(I_display, 10, 10,
"Brightness adjustment results");
171 std::stringstream ss_color;
172 ss_color << input_name <<
"_adjust_alpha=" << alpha <<
"_beta=" << beta <<
".png";
173 std::stringstream ss_gray;
174 ss_gray << input_name <<
"_adjust_alpha=" << alpha <<
"_beta=" << beta <<
"_gray.png";
175 display(I_display, I_color_res, I_color_adjust, I_gray_res, I_gray_adjust, I_gray_display,
176 "Brightness and contrast adjustment. Click to continue.", ss_color.str(), ss_gray.str());
195 ss_color << input_name <<
"_gamma=" << gamma <<
".png";
197 ss_gray << input_name <<
"_gamma=" << gamma <<
"_gray.png";
198 display(I_display, I_color_res, I_color_gamma_correction, I_gray_res, I_gray_gamma_correction, I_gray_display,
199 "Gamma correction. Click to continue.", ss_color.str(), ss_gray.str());
217 ss_color << input_name <<
"_" << gamma_name <<
".png";
219 ss_gray << input_name <<
"_" << gamma_name <<
"_gray.png";
220 display(I_display, I_color_res, I_color_gamma_correction, I_gray_res, I_gray_gamma_correction, I_gray_display,
221 "Gamma correction. Click to continue.", ss_color.str(), ss_gray.str(), gamma_name);
232 ss_color << input_name <<
"_eqHist.png";
234 ss_gray << input_name <<
"_eqHist_gray.png";
235 display(I_display, I_color_res, I_color_equalize_histogram, I_gray_res, I_gray_equalize_histogram, I_gray_display,
236 "Histogram equalization. Click to continue.", ss_color.str(), ss_gray.str());
253 ss_color << input_name <<
"_Retinex_scale=" << scale <<
"_scaleDiv=" << scaleDiv <<
"_level=" << level
254 <<
"_dynamic=" << dynamic <<
"_kernelSize=" << kernelSize <<
".png";
256 ss_gray << input_name <<
"_Retinex_scale=" << scale <<
"_scaleDiv=" << scaleDiv <<
"_level=" << level
257 <<
"_dynamic=" << dynamic <<
"_kernelSize=" << kernelSize <<
"_gray.png";
258 display(I_display, I_color_res, I_color_retinex, I_gray_res, I_gray_retinex, I_gray_display,
259 "Retinex. Click to quit.", ss_color.str(), ss_gray.str());
static const vpColor green
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
void setDownScalingFactor(unsigned int scale)
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 convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
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 ...
unsigned int getWidth() const
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
unsigned int getHeight() const
VISP_EXPORT void adjust(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, double alpha, double beta)
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 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 vpGammaMethod vpGammaMethodFromString(const std::string &name)
Cast a string into a vpGammaMethod.
VISP_EXPORT vpGammaColorHandling vpGammaColorHandlingFromString(const std::string &name)
Cast a string into a vpGammaColorHandling.
vpGammaColorHandling
How to handle color images when applying Gamma Correction.
VISP_EXPORT std::string vpGammaMethodList(const std::string &pref="<", const std::string &sep=" , ", const std::string &suf=">")
Get the list of available vpGammaMethod.
VISP_EXPORT std::string vpGammaColorHandlingList(const std::string &pref="<", const std::string &sep=" , ", const std::string &suf=">")
Get the list of available vpGammaColorHandling.
vpGammaMethod
Gamma Correction automatic methods.
VISP_EXPORT std::string vpGammaMethodToString(const vpGammaMethod &type)
Cast a vpGammaMethod into a string, to know its name.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.