Let’s say I have two very sparse binary images (0 is much more frequent than 1) and I want to calculate the per-pixel precision and recall of the two masks agreeing with each other. Basically asking: Where are the masks equal given that a pixel in A is true and the same given for B is true. We could do that along the lines of:
p = (a == b & a == 1).mean()
r = (a == b & b == 1).mean()
Now, I want to do this patch wise using a window. For example, given that pixel at i, j in image A is true. Is any pixel equal in image B given a region (KxK) around i, j? I also want to do this batchwise of course.
Is there any way doing this vectorized in pytorch? Currently, I can only come up with solutions using 3 for loops. I feel like this can somehow be done using maxpooling and a custom convolution kernel.