The image below only contains the black and white pixels after thresholding. I draw a rotated rectangle in grey on top of this image. Now I would like to count the number of black pixels within this rotated rectangle, but not including the black pixels outside the white rectangle-ish rectangle (i.e. number of the pixels within the white rectangle).
What is the best approach to do that? Shall I fill the area outside the white rectangle with white pixel? Any suggestions are welcomed.