How to detect a curve in a B&W image with a background grid?
Solution 1:
After several experiments (based on these examples) and tests, I ended up with this code:
let src = cv.imread('canvasInput');
let dst = new cv.Mat();
let M = cv.Mat.ones(3, 3, cv.CV_8U);
let anchor = new cv.Point(-1, -1);
cv.dilate(src, dst, M, anchor, 1, cv.BORDER_CONSTANT, cv.morphologyDefaultBorderValue());
cv.imshow('canvasOutput', dst);
src.delete(); dst.delete(); M.delete();
Probably it is possible to get even better results by concatenating multiple further filters, anyway already in this way I have acceptable results.
Full source image:
Edited, but data untouched:
Processed by above code ("dilate"):
Submitted to webplotdigitizer (look at settings on the right; yellow area is the only one processed by webplotdigitizer):
Raw processing by webplotdigitizer ; some stray points appear, but they can be easily manually deleted:
Cleaned up:
Re-plotted:
Note: in original image, horizontal and vertical scales are different: horizontal one is 4x w.r.t vertical one; resizing vertically 4x I get:
Overlaying final image on source image, we can see it matches perfectly:
Of course it would be better to have digitization inside the same source code, but this is another story...