GIMP Chat
http://gimpchat.com/

Remove only black spots in scanned documents?
http://gimpchat.com/viewtopic.php?f=28&t=20923
Page 1 of 1

Author:  Caleb13 [ Thu Jun 27, 2024 5:56 am ]
Post subject:  Remove only black spots in scanned documents?

Hello, I occassionaly use GIMP with BIMP plugin to mass-process scanned documents. Now I have hundreds of monochrome (1-bit) pages that have lots of isolated black spots. Unfortunately, they can't be avoided, because the source documents were printed on cheap paper with visible wood pieces. I know there are complicated manual methods how I could remove them, but they can't be effectively automated with BIMP.

So I tried to use G'MIC to remove them with "Despeckle", "Remove Hot Pixels" and "Repair Scanned Document". However, all these filters have a common problem: they also remove isolated white spots. I'm attaching a screenshot which showcases it - the filters fill the insides of number "4", which is highly undesirable. Is there some trick to remove only black spots?

Also, G'MIC doesn't work on 1-bit images, I have to convert them to grayscale first. I don't like doing that, because some filters may blur the edges, which worsens readability after converting back to 1-bit. Is there some way around it?

Thanks!

Attachments:
Example.png
Example.png [ 36.52 KiB | Viewed 249 times ]

Author:  ofnuts [ Sat Jun 29, 2024 2:26 pm ]
Post subject:  Re: Remove only black spots in scanned documents?

* Color-select Select the white
* Select > Grow by one pixel (or two, if you dare)
* Select > Shrink by one pixel (or two, id you dared)
* Bucket-fill selection with white.

Author:  Caleb13 [ Sat Jun 29, 2024 6:10 pm ]
Post subject:  Re: Remove only black spots in scanned documents?

I tried the grow/shrink method, but it's unusable, too many parts of text disappear.

I googled a way to do what I want, but it requires image processing program ImageJ that's usually used in medicine, tissue analysis and related fields. The results are very good, but it requires about 10 steps to get there, most importantly Analyze Particles function. (This forum doesn't allow me to post links, because I'm a new user.) And unfortunately, making ImageJ batch-process multiple files is rather complicated.

Anyway, I'm attaching an image that compares the results.

Attachments:
Example comparison.png
Example comparison.png [ 24.32 KiB | Viewed 160 times ]

Author:  PixLab [ Mon Jul 01, 2024 7:44 am ]
Post subject:  Re: Remove only black spots in scanned documents?

G'MIC > Details > Spotify to new layer

Attachment:
screenshot_20240701-203421.jpg
screenshot_20240701-203421.jpg [ 187.45 KiB | Viewed 91 times ]


On the new black layer select with the fuzzy select tool in mode addition the big black part (no more specs...)

Attachment:
screenshot_20240701-203715.jpg
screenshot_20240701-203715.jpg [ 219.72 KiB | Viewed 91 times ]


Then select the white layer in the layers' dialog and just drag and drop the white color from the FG/BG icon then Select > None

Result in one minute

Attachment:
screenshot_20240701-204320.jpg
screenshot_20240701-204320.jpg [ 188.65 KiB | Viewed 91 times ]

Author:  Steve [ Mon Jul 01, 2024 9:49 am ]
Post subject:  Re: Remove only black spots in scanned documents?

You might be able to make use of the script in the zipped folder below which converts single black pixels to white. It was written for use with RGB (no alpha channel) image mode so you would have to convert your mono image to RGB, run the script then convert back.

Please note for the script to work, the converted black pixels must be black 0,0,0 and the 8 pixels surrounding it must all be white 255,255,255

If you wish to try it place the script in your plug-ins folder, restart Gimp and it can be found at menu bar, '<Image>/Filters/Remove single black pixels'

It works on my Gimp 2.10.36

Hope it works for you

EDIT I've just noticed an omission from the script :oops:

Before running the script ensure the background colour is set to white 255, 255, 255. If it isn't any single black pixels on the very edge of the image will remain

Sorry for this

Attachment:
remove-single-black-pixels.zip [924 Bytes]
Downloaded 5 times

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/