How to transform the given function to be defined in another range?

35 Views Asked by At

I have the following weighting function: $$ w(\rho) = k \cdot(\rho^\alpha)\cdot(1-\rho)^\beta,$$ where $\rho$ represents a pixel value expressed as a double, i.e., it ranges from $0$ to $1$, and $ 1\le \alpha \le \beta$.

How can I convert this function so that it shows a curve similar to the given one but works for pixel values expressed as uint8, i.e., ranging from $0$ to $255$?

In the following example of the function I take values $\alpha = 1$; $\beta =6$ and $k =17.6$.

plot for <span class=$w(\rho) $ for $0\le \rho \le 1 $">

1

There are 1 best solutions below

5
On BEST ANSWER

The simple answer is to divide your uint8 values by $255$ as a float. That gives you a value in $[0,1]$ That is almost certainly good enough for this purpose.

The subtlety comes because the float values may be equally distributed on $[0,1]$. The inverse transformation would be to multiply the floats by $255$. Since the float will never be $1$ you would never get a result of $255$. Even if you round, $0$ and $255$ will only get hit half as often as the other values. The improvement would be to multiply by $256$ and round down. Now if the floats are equally distributed, so are the uint8s. For the uint8 to float you could then divide by $256$.