Getting clean lines from a smudged image

I would like to turn the blurry lines into sharp thin lines if possible. Get rid of all gray pixels and make them all black or white. But I have been having trouble doing this. Threshold doesnt get rid of all of the gray and when it does the lines are too fat. Sharpen also didnt uniformly reduce the line thickness. What can I do here?

I would like these lines to be the same width everywhere… Not sure if this is possible though.

out_rough

if you actually thresholded this, you would get precisely black and white, as a per-pixel decision. if you got any gray, you did something other than thresholding.

if you’re bothered by pixel noise, a light smoothing filter might do the trick.

there are more advanced filters that may do what you need. look into “bilateral filter” or “non-local means”. try them, see if they do what you want, or get you closer to the solution.

edit: so-called “unsharp masking” will produce sharper edges. may be suitable here.

line thickness, “thinning” might be a start, or not! for good results, this might require something nontrivial, i.e. literature research.

@c_dottel

As @crackwitz said, you can use a thinning algorithm. There are two in the extra module.
https://docs.opencv.org/master/df/d2d/group__ximgproc.html#ga37002c6ca80c978edb6ead5d6b39740c

The optional third argument is the algorithm. Zhang-Suen is the default one, and a good choice.

You can also try Canny. It gets 1 pixel thin lines for edges. Canny won’t give you a line but the contour of the line. It uses two threshold you can play with.
https://docs.opencv.org/master/da/d22/tutorial_py_canny.html
image