71

What does the cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1); do in OpenCV?

I went through the documentation and was unable to understand what alpha, beta, NORM_MINMAX and CV_8UC1 actually do. I am aware alpha sets the lower and beta the higher bound. CV_8UC1 stands for an 8-bit unsigned single channel. But what exactly these arguments do to the picture is what I am unable to comprehend.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
user1179510
  • 1,003
  • 1
  • 14
  • 24
  • **Use `CV_8U` instead for the `dtype` argument.** “[_`dtype`: when negative, the output array has the same type as `src`; otherwise, **it has the same number of channels as `src`** and the depth = `CV_MAT_DEPTH(dtype)`._](https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga87eef7ee3970f86906d69a92cbf064bd)” The `dst` will always have the same number of channels as the `src`. – Константин Ван Nov 19 '22 at 04:39

2 Answers2

76

When the normType is NORM_MINMAX, cv::normalize normalizes _src in such a way that the min value of dst is alpha and max value of dst is beta. cv::normalize does its magic using only scales and shifts (i.e. adding constants and multiplying by constants).

CV_8UC1 says how many channels dst has.

The documentation here is pretty clear: http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#normalize

chappjc
  • 30,359
  • 6
  • 75
  • 132
carlosdc
  • 12,022
  • 4
  • 45
  • 62
  • What do alpha and beta mean in the image. As far as I know alpha stood for minimum range and beta for max.So if I am converting to grayscale shouldnt alpha be 0 and beta be 1 if I am using a single channel? – user1179510 Aug 19 '12 at 03:51
  • alpha and beta are the highest and lowest value in the dst image, respectively. – carlosdc Aug 19 '12 at 03:53
  • 1
    So when I am using a single channel it should ideally be 0 to 1 right? Or am I mistaken here? – user1179510 Aug 19 '12 at 03:56
  • 4
    0 to 255 are the physical limits of your array: you can't store anything above 255 or below 0. What values to use it depends on what limits you need: if you use 5 and 20 there won't be anything below 5 or above 20. – carlosdc Aug 19 '12 at 04:03
  • But single channels simply use 0 and 1 right? So the 0 and 255 are kind of redundant? – user1179510 Aug 19 '12 at 04:22
  • 4
    No... single channel use one channel but the signal is between 0 and 255. – carlosdc Aug 19 '12 at 04:42
  • OKay. I guess now I need to read up more on channels and what they are. Thanks for the help! – user1179510 Aug 19 '12 at 04:48
  • can you use this function to normalize a set of images best on mean and std of all images not just a single image? – Jürgen K. Sep 24 '19 at 12:23
  • @carlosdc `alpha and beta are the highest and lowest value in the dst image, respectively.` isn't it the reverse; alpha is lower limit so it is the minimum and beta is upper limit so it is the maximum in the dst? – mcy Jul 23 '20 at 14:12
  • 0 to 255 limits are related to `CV_8UC1`, it is different for other types – rafoo Oct 21 '22 at 03:12
  • “_`dtype`: when negative, the output array has the same type as `src`; otherwise, **it has the same number of channels as `src`** and the depth = `CV_MAT_DEPTH(dtype)`._” No, you shouldn’t specify how many channels `dst` has, because it is always the same with the `src`. **Use `CV_8U` instead.** – Константин Ван Nov 19 '22 at 04:37
0

There are several types of normalization in Opencv.

Try running samples in the Online OpenCV-Flow tool to better understand each type.

Normalize Sample