45 #include <visp3/core/vpImageTools.h> 49 std::cout <<
"Test vpImageTools::binarise() with different data types." << std::endl;
51 unsigned int width = 5, height = 4;
52 unsigned char *uchar_array =
new unsigned char[width * height];
53 double *double_array =
new double[width * height];
55 for (
unsigned char i = 0; i < width * height; i++) {
58 rgba_array[i] =
vpRGBa(i, i, i, i);
65 std::cout <<
"I:" << std::endl;
66 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
67 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
68 std::cout << static_cast<unsigned>(I[i][j]) <<
" ";
70 std::cout << std::endl;
73 std::cout <<
"\nI_double:" << std::endl;
74 for (
unsigned int i = 0; i < I_double.getHeight(); i++) {
75 for (
unsigned int j = 0; j < I_double.getWidth(); j++) {
76 std::cout << I_double[i][j] <<
" ";
78 std::cout << std::endl;
81 std::cout <<
"\nI_rgba:" << std::endl;
82 for (
unsigned int i = 0; i < I_rgba.getHeight(); i++) {
83 for (
unsigned int j = 0; j < I_rgba.getWidth(); j++) {
84 std::cout << static_cast<unsigned>(I_rgba[i][j].R) <<
" ; " << static_cast<unsigned>(I_rgba[i][j].G) <<
" ; " 85 <<
static_cast<unsigned>(I_rgba[i][j].B) <<
" ; " << static_cast<unsigned int>(I_rgba[i][j].A)
88 std::cout << std::endl;
96 std::cout <<
"\nI binarise:" << std::endl;
97 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
98 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
99 std::cout << static_cast<unsigned>(I[i][j]) <<
" ";
101 std::cout << std::endl;
104 std::cout <<
"\nI_double binarise:" << std::endl;
105 for (
unsigned int i = 0; i < I_double.getHeight(); i++) {
106 for (
unsigned int j = 0; j < I_double.getWidth(); j++) {
107 std::cout << I_double[i][j] <<
" ";
109 std::cout << std::endl;
112 std::cout <<
"\nI_rgba binarise:" << std::endl;
113 for (
unsigned int i = 0; i < I_rgba.getHeight(); i++) {
114 for (
unsigned int j = 0; j < I_rgba.getWidth(); j++) {
115 std::cout << static_cast<unsigned>(I_rgba[i][j].R) <<
" ; " << static_cast<unsigned>(I_rgba[i][j].G) <<
" ; " 116 <<
static_cast<unsigned>(I_rgba[i][j].B) <<
" ; " << static_cast<unsigned>(I_rgba[i][j].A) << std::endl;
118 std::cout << std::endl;
124 unsigned char *uchar_array1 =
new unsigned char[width * height];
125 unsigned char *uchar_array2 =
new unsigned char[width * height];
126 for (
unsigned int i = 0; i < 256; i++) {
127 uchar_array1[i] = (
unsigned char)i;
128 uchar_array2[i] = (
unsigned char)i;
134 unsigned char threshold1 = 50, threshold2 = 200;
135 unsigned char value1 = 4, value2 = 127, value3 = 250;
139 for (
unsigned int i = 0; i < height; i++) {
140 for (
unsigned int j = 0; j < width; j++) {
141 if (I_uchar1[i][j] != I_uchar2[i][j]) {
142 std::cerr <<
"Results are different between iterate and LUT methods !" << std::endl;
151 unsigned char *uchar_array_perf_lut =
new unsigned char[width * height];
152 unsigned char *uchar_array_perf_iterate =
new unsigned char[width * height];
153 for (
unsigned int i = 0; i < width * height; i++) {
154 uchar_array_perf_lut[i] = (
unsigned char)i;
155 uchar_array_perf_iterate[i] = (
unsigned char)i;
161 unsigned int nbIterations = 100;
163 for (
unsigned int cpt = 0; cpt < nbIterations; cpt++) {
167 std::cout <<
"Iterate: " << t1 <<
" ms for " << nbIterations <<
" iterations." << std::endl;
170 for (
unsigned int cpt = 0; cpt < nbIterations; cpt++) {
174 std::cout <<
"LUT: " << t2 <<
" ms for " << nbIterations <<
" iterations." << std::endl;
176 std::cout <<
"\ntestImageBinarise ok !" << std::endl;
unsigned int getWidth() const
VISP_EXPORT double measureTimeMs()
unsigned int getHeight() const