nice!
I made some computations to understand this alpha thing. The formula I used e1/(e1+e2)
turns out to be a very good approximation of the horizontal distance (not squared) between the pixel and the ideal circle. (and e
is not necessarily small, it’s an integer between -2r and 2r, where r is the radius).
Now comes the physics. My guess would be that the alpha value is (linearly?) related to the “intensity” of the pixel (I should rather say the “value”). But then the energy is the square of the intensity. My second guess is that the eye rather perceives the energy, and not the intensity.
Now look at the simple situation with an ideal pixel at position (float)x in [0,1]. We want to approximate it by two physical pixels at x=0 and x=1. The question is how to compute the intensity of each pixel, i1 and i2. [which is the same as the alpha value, if my first guess is correct]. The surface proportions of the ideal pixel are p1 = 1-x and p2 = x. Therefore we should take
i1= sqrt(1-x) and i2 = sqrt(x),
so that i1^2 + i2^2 = 1
. So you are right, we need the square root (or a trick to approximate it).
BUT, it’s not clear (to me) that the alpha channel gives the physical intensity. If we assume instead that the alpha channel is roughly proportionnal to the energy, then taking
i1 = 1-x and i2 = x
,
(as I did in my code), it would give the correct answer.
In any case, I’d be curious to know whether the bare eye is able to tell the difference between the two formulas, and to tell which one ‘looks nicer’ (which, afterall, is what we want).
EDIT: after some googling, it seems that most people in computer vision use directly the alpha value as a indicator of “luminous intensity” (which, I called energy, I think). And they simply take the area proportion of pixel to compute the alpha. In this case, my second formula (without the sqrt) would be correct.