fbol
May 25, 2023, 10:24am
1
Hello,

I have a CV_32FC1 image `img`

containing values in the approximate range `-1e-04, 1e-03`

.

I want to visualize this image, so I normalize it as follows

```
cv::Mat disp;
cv::normalize(img, disp, 0, float_max, cv::NORM_MINMAX, CV_32FC1);
```

where float_max is the maximum value a `float`

can hold.

When I print to terminal the intensity values of `disp`

they are all 0.
I was expecting the maxima of the image to be near `1e13`

and the minima to be 0.

Why is that? Am I missing something or is this a bug?

Doc is here

A minimal example is welcome. May be you can modify doc example

```
vector<double> positiveData = { 2.0, 8.0, 10.0 };
vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax;
// Norm to probability (total count)
// sum(numbers) = 20.0
// 2.0 0.1 (2.0/20.0)
// 8.0 0.4 (8.0/20.0)
// 10.0 0.5 (10.0/20.0)
normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1);
// Norm to unit vector: ||positiveData|| = 1.0
// 2.0 0.15
// 8.0 0.62
// 10.0 0.77
normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2);
// Norm to max element
// 2.0 0.2 (2.0/10.0)
// 8.0 0.8 (8.0/10.0)
// 10.0 1.0 (10.0/10.0)
normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF);
// Norm to range [0.0;1.0]
// 2.0 0.0 (shift to left border)
// 8.0 0.75 (6.0/8.0)
// 10.0 1.0 (shift to right border)
normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX);
```

fbol
May 25, 2023, 10:53am
4
Hello Laurent, thak you for your answer.

In the end, my problem was that all values in the image were equal, so normalization clipped everything to 0.

Regards

No please read doc
double alpha = `1`

,
double beta = `0`

,

You set alpha to 0

fbol
May 25, 2023, 12:47pm
6
The doc specifies that when` normType`

=` NORM_MINMAX`

, then `alpha`

is the minimum intensity value in `dst`

, while `beta`

is the maximum.

Regards

fbol:

`cv::normalize(img, disp, 0, float_max, cv::NORM_MINMAX, CV_32FC1);`

Ok forget everything
I will write a minimal example for you. I think I have to guess your problem…

```
Mat img_float = (Mat_<float>(2, 3) << 1.4, 3, 5, -1, -2.2, 0);
Mat dst;
cv::normalize(img_float, dst, 0, 1, cv::NORM_MINMAX, CV_32FC1);
cout << img_float << endl;
cout << dst << endl;
cv::normalize(img_float, dst, 0, FLT_MAX, cv::NORM_MINMAX, CV_32FC1);
cout << img_float << endl;
cout << dst << endl;
```

Result

```
[1.4, 3, 5;
-1, -2.2, 0]
[0.5, 0.72222221, 1;
0.16666667, 0, 0.30555555]
[1.4, 3, 5;
-1, -2.2, 0]
[1.7014118e+38, 2.4575948e+38, inf;
5.671373e+37, 0, 1.0397517e+38]
```

Now you are sure that you 've got an inf value that’s fun to process

fbol
May 25, 2023, 3:45pm
8
Hello Laurent, thanks for your answer and research.

My problem has been solved since I wrote the second post. Of course float_max was referring to the maximum numerical value a float can hold (not infinity).

As I said in my second post, the problem was that all values in the range were the same, and were therefore squeezed down to zero.

Have a nice day

float_max is not a c++ key word I have to guess it is FLT_MAX