36#include <visp3/core/vpImage.h>
37#include <visp3/core/vpIoTools.h>
38#include <visp3/core/vpMath.h>
39#include <visp3/imgproc/vpImgproc.h>
40#include <visp3/io/vpImageIo.h>
41#include <visp3/io/vpParseArgv.h>
50#define GETOPTARGS "cdi:o:h"
52void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
53bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
64void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
67Test imgproc functions.\n\
70 %s [-i <input image path>] [-o <output image path>]\n\
77 -i <input image path> %s\n\
78 Set image input path.\n\
79 From this path read \"Klimt/Klimt.pgm\"\n\
81 Setting the VISP_INPUT_IMAGE_PATH environment\n\
82 variable produces the same behaviour than using\n\
85 -o <output image path> %s\n\
86 Set image output path.\n\
87 From this directory, creates the \"%s\"\n\
88 subdirectory depending on the username, where \n\
89 Klimt_grey.pgm output image is written.\n\
93 ipath.c_str(), opath.c_str(), user.c_str());
96 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
109bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
123 usage(argv[0], NULL, ipath, opath, user);
132 usage(argv[0], optarg_, ipath, opath, user);
138 if ((c == 1) || (c == -1)) {
140 usage(argv[0], NULL, ipath, opath, user);
141 std::cerr <<
"ERROR: " << std::endl;
142 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
149int main(
int argc,
const char **argv)
152 std::string env_ipath;
153 std::string opt_ipath;
154 std::string opt_opath;
157 std::string filename;
158 std::string username;
160#if VISP_HAVE_DATASET_VERSION >= 0x030600
161 std::string ext(
"png");
163 std::string ext(
"pgm");
171 if (!env_ipath.empty())
176 opt_opath =
"C:/temp";
185 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
190 if (!opt_ipath.empty())
192 if (!opt_opath.empty())
204 usage(argv[0], NULL, ipath, opt_opath, username);
205 std::cerr << std::endl <<
"ERROR:" << std::endl;
206 std::cerr <<
" Cannot create " << opath << std::endl;
207 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
214 if (!opt_ipath.empty() && !env_ipath.empty()) {
215 if (ipath != env_ipath) {
216 std::cout << std::endl <<
"WARNING: " << std::endl;
217 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
218 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
219 <<
" we skip the environment variable." << std::endl;
224 if (opt_ipath.empty() && env_ipath.empty()) {
225 usage(argv[0], NULL, ipath, opt_opath, username);
226 std::cerr << std::endl <<
"ERROR:" << std::endl;
227 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
228 <<
" environment variable to specify the location of the " << std::endl
229 <<
" image path where test images are located." << std::endl
245 std::cout <<
"Read image: " << filename << std::endl;
248 std::cout <<
"Image: " << I_color.
getWidth() <<
"x" << I_color.
getHeight() << std::endl;
251 double alpha = 1.5, beta = -10.0;
254 vp::adjust(I_color, I_color_adjust, alpha, beta);
256 std::cout <<
"Time to do color adjust: " << t <<
" ms" << std::endl;
267 std::cout <<
"Time to do color histogram equalization: " << t <<
" ms" << std::endl;
279 std::cout <<
"Time to do color gamma correction: " << t <<
" ms" << std::endl;
290 std::cout <<
"Time to do color retinex: " << t <<
" ms" << std::endl;
301 std::cout <<
"Time to do color contrast stretching: " << t <<
" ms" << std::endl;
312 std::cout <<
"Time to do color HSV contrast stretching: " << t <<
" ms" << std::endl;
320 const float sigma = 1.0f;
324 std::cout <<
"Time to do color unsharp mask: " << t <<
" ms" << std::endl;
335 std::cout <<
"Time to do color CLAHE: " << t <<
" ms" << std::endl;
348 std::cout <<
"\nRead image: " << filename << std::endl;
359 std::cout <<
"Time to do grayscale adjust: " << t <<
" ms" << std::endl;
370 std::cout <<
"Time to do grayscale histogram equalization: " << t <<
" ms" << std::endl;
382 std::cout <<
"Time to do grayscale gamma correction: " << t <<
" ms" << std::endl;
393 std::cout <<
"Time to do grayscale contrast stretching: " << t <<
" ms" << std::endl;
404 std::cout <<
"Time to do grayscale unsharp mask: " << t <<
" ms" << std::endl;
415 std::cout <<
"Time to do grayscale CLAHE: " << t <<
" ms" << std::endl;
423 std::cerr <<
"Catch an exception: " << e.
what() << std::endl;
error that can be emitted by ViSP classes.
const char * what() const
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)
Definition of the vpImage class member functions.
void halfSizeImage(vpImage< Type > &res) const
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
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)
VISP_EXPORT void adjust(vpImage< unsigned char > &I, double alpha, double beta)
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
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)
vp_deprecated VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, unsigned int size=7, double weight=0.6)
VISP_EXPORT double measureTimeMs()