Methods to Clean Worksheet Pictures

My son’s going to the 6th grade and my daughter came to school today. This means I will have to deal with this topic for quite another while and therefore I am asking for help.

When I ask the parents of classmates or my son asks his classmates for scans of worksheets he missed, e.g. due to being sick, I often (this means: always) get smartphone pictures back. Here’s an example (I searched the web, as I do not want to post an original one because of copyright):


Typically they have several flaws, and the example above is not a particularly bad example, more the mean. The flaws are:

  • Uneven light distribution resulting in uneven background as well as foreground color
  • Different kinds of distortion, especially
    • linear distortion from camera angle
    • other distortions from uneven paper

Unfortunately I struggle to clean such sheets for printing and therefore I am asking how I could achieve what I think would solve the problem and if you have other ideas.

My ideas:

Linear distortion

The unified transform tool is useful, however, it would be most useful in correction mode, but as it does not know the focal length, it always returns a stretched result (page too high or too wide). How can I solve this?

Uneven light

What I think would help is a tool where one can sample the background at different positions (manually given) and gimp would calculate a correction based on the interpolation of these points. Is this somehow possible (maybe in several steps)?

Other distortions

I have no clue how to solve this …

Try auto input in the levels tool to get a more readable document. I am not sure that all the problems can be resolved in an efficient manner for a worksheet.

1 Like

Thanks for the suggestion. Unfortunately, as far as I understand, the auto levels is a global operation, which fails in case of too much change in illumination. It will be very useful once the local differences are equalized …

As you say, it is not the worst example, so this is very much a maybe.

The old Gimp plugin Curve Bend for straightening. Old as in when computer monitors were a lot smaller.
see: 5.19. Curve Bend (about time that page was updated)

Lighten it up a little using the levels tool.

https://i.imgur.com/kloODUX.mp4

and a one minute video. I put a border around to make it easier, but not absolutely necessary. Best of luck

1 Like

I think your time is better served using a local AI model to extract the data, then copying it to a libreoffice doc and printing instead. It’s completely private, fast, and you don’t need a lot of hardware to run it (Gemma 4B runs on phones) and gets the job done. As long as the worksheets don’t have images, it should do the trick.

Here is an example, running Gemma3 12B locally, took 20 seconds on an rtx3080:

I hope this doesn’t break the AI rules on the forum, as the model is ran locally and it’s pretty much just functioning as a very good OCR.

2 Likes

This tool looks like the ideal solution for the bending, I didn’t know it exists. However, on my small 4k laptop display the preview is tiny. Maybe we have a gegl ported non-destructive version one day, but I’ll definitely try it even with the small preview next time I have this issue.

How did you run it? I’ve got a decent laptop gpu, so it should be no issue to run the model, but I am unsure which framework I need to use it (i’m on linux).

It’s for sure a very good solution for the sheets without images.

Unfortunately, most of them do. So I am still searching a solution to get a decent paper color model based on sample points …

1 Like

On the phone you can download googles AI Edge Gallery on GitHub. On the PC the easiest software to setup is Ollama, but it’s not fully open source. If you are more at ease with these things you can try llama cpp and open webui. The Gemma models are all on hugging face, search for the gguf version. Though if you use Ollama it downloads the model for you

1 Like

A nice tool providing a unified interface, whether it’s a local model or one hosted in the cloud:
https://llm.datasette.io/en/stable/

2 Likes

Need it on the laptop.

Hm, a no-go for now.

C++ api, right? I am not a programmer … i mean, technically, i have been developing component models based on neural networks with tensorflow/keras, pytorch, and scikit-learn in combination at work in a research project, but i am even not able to run a model from huggingface … strange :crazy_face:.

This looks good, but i need to update my os before it will run smoothly. Non-web app would be easier …

This looks reasonably simple, but I was not able to figure out if it is compatible with gemma. I’ll need to have a deeper look I think.

I also worked with chainner in the pase, but i also did not figure out if gemma is compatible with it yet. Still, a lot to learn for me.

Thanks to both of you for the suggestions, though.

It is:

2 Likes

No, it’s a model loader with a simple web interface and openai compatible apis. The cpp in the name is just because it’s written in cpp.

After you compile or install it it’s a single command to run whatever model you have downloaded

1 Like