44 #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) << std::endl;
87 std::cout << std::endl;
90 vpImageTools::binarise(I, (
unsigned char) 5, (
unsigned char) 12, (
unsigned char) 0, (
unsigned char) 127, (
unsigned char) 255);
94 std::cout <<
"\nI binarise:" << std::endl;
95 for(
unsigned int i = 0; i < I.
getHeight(); i++) {
96 for(
unsigned int j = 0; j < I.
getWidth(); j++) {
97 std::cout << static_cast<unsigned>(I[i][j]) <<
" ";
99 std::cout << std::endl;
102 std::cout <<
"\nI_double binarise:" << std::endl;
103 for(
unsigned int i = 0; i < I_double.getHeight(); i++) {
104 for(
unsigned int j = 0; j < I_double.getWidth(); j++) {
105 std::cout << I_double[i][j] <<
" ";
107 std::cout << std::endl;
110 std::cout <<
"\nI_rgba binarise:" << std::endl;
111 for(
unsigned int i = 0; i < I_rgba.getHeight(); i++) {
112 for(
unsigned int j = 0; j < I_rgba.getWidth(); j++) {
113 std::cout << static_cast<unsigned>(I_rgba[i][j].R) <<
" ; " << static_cast<unsigned>(I_rgba[i][j].G) <<
" ; "
114 <<
static_cast<unsigned>(I_rgba[i][j].B) <<
" ; " << static_cast<unsigned>(I_rgba[i][j].A) << std::endl;
116 std::cout << std::endl;
123 unsigned char *uchar_array1 =
new unsigned char[width*height];
124 unsigned char *uchar_array2 =
new unsigned char[width*height];
125 for(
unsigned int i = 0; i < 256; i++) {
126 uchar_array1[i] = (
unsigned char) i;
127 uchar_array2[i] = (
unsigned char) i;
133 unsigned char threshold1 = 50, threshold2 = 200;
134 unsigned char value1 = 4, value2 = 127, value3 = 250;
138 for(
unsigned int i = 0; i < height; i++) {
139 for(
unsigned int j = 0; j < width; j++) {
140 if(I_uchar1[i][j] != I_uchar2[i][j]) {
141 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;
177 std::cout <<
"\ntestImageBinarise ok !" << std::endl;
unsigned int getWidth() const
VISP_EXPORT double measureTimeMs()
unsigned int getHeight() const