Search code examples
image-processingimagemagickpngocrhandwriting-recognition

Removing the entire background from a mathematical formula image


Consider the following image:

enter image description here

I would like to remove the entire background (everything that does not belong to the) to be left only with the integral. My purpose is to make it easier to get the integral in LaTeX from OCR.


Solution

  • Is this what you want? Using Imagemagick, I do a division normalization followed by a thresholding.

    Input:

    enter image description here

    convert image.png \( +clone -blur 99 \) +swap -compose divide -composite -negate -threshold 18% -negate result.png
    

    enter image description here

    Adjust the threshold as desired.

    ADDITION

    Add morphology to thicken the lines

    convert image.png \( +clone -blur 99 \) +swap -compose divide -composite -negate -threshold 25% -negate -morphology erode diamond:1 result.png
    

    enter image description here