It is currently Tue Jul 02, 2024 12:05 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Remove only black spots in scanned documents?
PostPosted: Thu Jun 27, 2024 5:56 am  (#1) 
Offline
New Member

Joined: Jun 26, 2024
Posts: 2
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 202 times ]
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Remove only black spots in scanned documents?
PostPosted: Sat Jun 29, 2024 2:26 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
* 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.

_________________
Image


Top
 Post subject: Re: Remove only black spots in scanned documents?
PostPosted: Sat Jun 29, 2024 6:10 pm  (#3) 
Offline
New Member

Joined: Jun 26, 2024
Posts: 2
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 113 times ]
Top
 Post subject: Re: Remove only black spots in scanned documents?
PostPosted: Mon Jul 01, 2024 7:44 am  (#4) 
Online
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 790
Location: SEA - South East Asia
G'MIC > Details > Spotify to new layer

Attachment:
screenshot_20240701-203421.jpg
screenshot_20240701-203421.jpg [ 187.45 KiB | Viewed 44 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 44 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 44 times ]

_________________
Patrice


Top
 Post subject: Re: Remove only black spots in scanned documents?
PostPosted: Mon Jul 01, 2024 9:49 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 199
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 2 times


Top
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Use of Fuzzy Select tool to remove white background from black text

2

No new posts Attachment(s) Creating transparent spots using patterns in GIMP

12

No new posts Many of my GEGL Filters are getting tutorial documents

4

No new posts Scan multiple documents gimp, gmic, gscan2pdf

1

No new posts Attachment(s) Remove Stain from Image

5



* Login  



Powered by phpBB3 © phpBB Group