pycairo
pycairo copied to clipboard
Getting rasterized pixels
Let's say I draw a bezier curve using curve_to
and then stroke
. Is there a way to return the pixels that were changed by this operation?
Whats the use-case ? I don't believe it is directly possible (though on a low level, cairos span-compositor may heve the information). It may be possible to work out a slightly different approach to achieve what you want.
Here is a slightly inefficient approach that may work:
- Use stroke-extents to get the area that will be painted.
- Create a greyscale bitmap* the size of that area
- Paint the path onto in black
- Check which pixels are non-white
*Making the intermediate bitmap 8bit greyscale, or 1 bit black and white should help performance here.
I'm running an optimization algorithm which needs to calculate the mean square difference between two images along the path of a line. I have implemented your solution as a workaround.
I was hoping for an API similar to skimage.
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = bezier_curve(1, 5, 5, -2, 8, 8, 2)
>>> img[rr, cc] = 1
Suggestion: implement your own Bézier rendering algorithm. The De Casteljau construction is not hard to implement.