After implementing a canny edge detector I have to compare the results to the ones detected by a human, and calculate precision and recall (by comparing each pixel). Both images are binary. The thing is, I have to allow a pixel shift of size one between the images. That means that if I have a value of 1 in E(i,j) and the reference image has it for example at GT(i-1,j), there would still be a match. This shift is individual to each pixel and could be at any direction. For the implementation I must use either a mask or the function cv2.dilate(), but since by using dilate we are turning on more pixels, each of those could be matched with one in the reference image, therefore creating multiple matches for each original pixel, which is not allowed. Does anyone have an idea how to allow the pixel shift without creating multiple matches per pixel?
Asked
Active
Viewed 362 times
0
-
You could perhaps create 8 different images of your canny-edge-detected image such thay they are shifted in each of the 8 directions. Let's call these 8 images: `shifted[n]` (where `n` belongs to `[0,8)`). Now, assuming you'd want to match the both set and unset pixels and assuming those pixels are all either 1 or 0, you could probably do: `result[i][j] = any(canny[i][j] ^ shifted[n][i][j] for n in range(8))`. You'd have to perhaps do more than this (bounds checking, normalizing of pixels to 1 and 0, and maybe some more). – UltraInstinct Nov 16 '20 at 16:25
-
Take the minimum discrepancy between the pixel x, y in the first images and the 9 pixels in the facing 3x3 neighborhood in the other. – Nov 16 '20 at 16:33
-
Thank you, but I need solutions with either a convolution mask or cv2.dilate() – Inbaral Nov 16 '20 at 16:59