Search code examples
pythonopencvsmoothing

How to smooth and make thinner these very rough images using OpenCV?


I have some black and white images of a single digit. I am using a NN model trained on MNIST to classify them. However, the digits are too rough and thick compared to the MNIST dataset. For example:

enter image description here

TLDR: I need to smoothen image and possibly make overall shape thinner using OpenCV.


Solution

  • You will most likely benefit from morphological operations. Specifically it sounds like you want erosion.

    You do have some noise though. You should try OpenCV's smoothing operations. Based on my experience, I think you need to use a median blur with a kernel area of maybe around 9 (although it depends on what you want). Then you need to use erode.