Does C have a quantization function?

I have a buffer with many positive 16-bit values ​​(which are stored as doubles) that I would like to quantize to 8 bits (0-255 values).

According to Wikipedia, the process will look like this:

  • Normalize 16-bit values. That is, find the greatest and share with it.
  • Use the formula Q (x) with M = 8.

So, I wonder if C has a function that can do this quantization, or does anyone know of a C implementation that I could use?

Lots of love, Louise

+3
source share
3 answers

Assuming the value dis in the range [0.0, max]:

unsigned char quantize(double d, double max)
{
    return (unsigned char)((d / max) * 255.0);
}

, "16- "; 64- IEEE-754. , , .

+2

, - 16 PCM-, - 8- PCM, .

8- PCM , , 128 . (, )

, . ,

double dMax = max_of_all_values(); // 
...
foreach (dValue in array_of_doubles)
{
   signed char bValue = (signed char)((dValue / dMax)*127.0);
}

, , , , , .

: char , 8- PCM, , .

: , . , , ( )

+3

, , " 16- ( )" ; 16 , , .

, , 16- , 1.0 ( 0.0 <= s <= 1.0), , , 8- , 255.

unsigned char s8 = s * 255 ;

0.0 <= s <= 1.0, 0.0 <= s <= max, :

unsigned char s8 = s / max * 255 ;

, , , ; , , ( , , , , , , μ-lay A-law).

+1

Source: https://habr.com/ru/post/1726671/


All Articles