enterthevoidf22:

what i mean is that i count the non-zero elements before and after transform and getting more non-zero after tranform for some pictures, less non-zero for others, and also sometimes getting the right amount.


This might be indeed expected, if e.g. a single input pixel with a non-zero value “lands” on multiple output pixel locations after the rotation. I assumed that the nearest interpolation would make sure to select a single output location, but this doesn’t seem to be the case.
E.g. if you have 4 single pixels with a non-zero value in the input image creating the edges of a rectangle, the rotated image would create a rotated rectangle, but each edge might be bigger or smaller.
For your use case you could thus use the keypoint coordinates directly instead of rotating an image.