0

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.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
PaulS
  • 21,159
  • 2
  • 9
  • 26
  • Define remove? What exactly do you want to remove. Is it the background texture or part of the formula? If the background texture, what "color" do you want in the background or transparency? Please be specific when asking questions. Please read the information guides in the **help center** (https://stackoverflow.com/help), in particular, "How to Ask A Good Question" (https://stackoverflow.com/help/how-to-ask) and "How to create a Minimal, Reproducible Example" (https://stackoverflow.com/help/minimal-reproducible-example). – fmw42 Jul 20 '23 at 15:27
  • I have clarified what I thought was obvious: I want to remove everything that does not belong to the formula. To get the formula as LaTeX code, only the part of the image that belongs to the formula is needed. – PaulS Jul 20 '23 at 15:39
  • you have not said what you want (color) in place of your background – fmw42 Jul 20 '23 at 16:00
  • You also did not specify a programming languange – fmw42 Jul 20 '23 at 16:01
  • that is _handwriting_. any OCR for handwriting would be robust enough to handle those faint lines on the paper. any processing will just make the data worse. stop doing the work for AI. AI can learn to handle this a lot better than any processing you can do. – Christoph Rackwitz Jul 20 '23 at 17:27
  • Thanks, @ChristophRackwitz, for your comment. Maybe, you are right, but I was just trying the scientific method: experimenting to learn whether preprocessing an image helps or not OCR of mathematical formulas. – PaulS Jul 20 '23 at 17:51

1 Answers1

1

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

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Thanks, @fmw42! That is something like you did that I want. With a threshold of 25% one can get rid of all small lines (that does not belong to the formula). Can now we make the formula as been drawn by a thicker line? – PaulS Jul 20 '23 at 15:52
  • 1
    See my ADDITION in my answer – fmw42 Jul 20 '23 at 16:57