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

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$$.

$w(\rho)$ for $$0\le \rho \le 1$$">

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$$.

• thanks sir, I have done the same earlier and I got zeros instead of ones during conversion of float to uint8 for the values like this (6.376246841303954e-14) and so I incremented every value by one . I know its a dumb question to ask but , I wanted to know that ,given x < P < y ranges for a variable P in function and to use it for another range x1 < P < y1 ,doing a proportional conversion just like we did earlier is fine right. – MOHANTEJA Mar 13 at 18:00
• @MOHANTEJA I don't understand: for me it seems correct that a pixel value expressed as double is $6.376246841303954\cdot e^{-14}$ and expressed as uint8 is $0$. All doubles between $0$ and $1/256$ should be mapped to $0$ when expressed as uint8. – simonet Mar 13 at 21:21
• @MOHANTEJA: I am surprised that you can get a value of $6.37E-14$. That is extremely small. Most pixel values have only 16 or 24 bits, but this needs 44 to represent it. I suspect you are not interpreting the input correctly. If it is a correct input, it should be mapped to 0, as should any value less than $1/256$ – Ross Millikan Mar 13 at 23:33
• @RossMillikan I using the weight function in denominator of a division.so I had to make zeros to ones in order to prevent division by zero, sorry I didn't mentioned that in the earlier comment. – MOHANTEJA Mar 14 at 13:15
• [the matlab code I have used ](gist.github.com/mohanteja1/775aa179df41cac21a500ebc69e6aa14 ) – MOHANTEJA Mar 14 at 13:57