It is currently Mon Apr 15, 2024 8:01 am


All times are UTC - 5 hours [ DST ]


Switch to mobile style

Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: Batch script for image brightness equalization?
PostPosted: Sat Nov 04, 2017 10:56 pm  (#1) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
Hello,

I'am newbie on the forum and I need some help. I should process a set of images, actually photos of a rare book very important for me. For that purpose I'm using ScanTailor program but I have a problem. The photos are made in bad lighting environment, so the images of the book pages are unevenly illuminated. The ScanTailor is bad in processing of such images.
I found a tutorial how to solve the problem using Gimp:

To counter that uneven level of brightness you can simulate a highpass filter in GIMP.

- Duplicate the background layer (the image you want to homogenize).
- On this duplicate use Filter / Blur / Gaussian Blur. The pixels you enter in this filter determine how big the parts (that need to be homogenzied) should be. In this texture the brigher parts are distributed over a bigger part of the image, therefore I take a larger value – around 20-40 px.
- Then do an Colors / Invert
- Colors / Desaturate
- Set the layers mode to “Overlay”

By doing this the too bright parts get a little darker and vice versa – thats how the images brightness is equalized.

Make the effect stronger by just duplicating the “overlay”-layer.



After applying all steps from the tutorial I got a result that works for me.
Now I need to repeat it about 700 times and I do not like it :roll: .

So, is there any way to automatize this procedure for a set of images? I must say that I do not know anything about GIMP scripting so if there is a good soul out there that can help, I will need detail instructions :oops: .
Also, if there is some already existing different solution that do the job I will gladly accept it.

Thanks in advance!


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: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 4:15 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
I don't know a way to automate that procedure for a set of images, However, if you have G'MIC installed in GIMP (if not get it from: http://gmic.eu/download.shtml), you could try the High pass filter under the 'Details' section to perhaps create a similar effect, if you play around with the settings, see whether the preview looks good, then you can make the effect happen on all layers - and it's quite quick too!.. Or, apply the effect to a single layer only and check the result first before deciding to go through with it on all layers.


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 6:41 am  (#3) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
Zero01, thanks a lot. Even it does not solve my problem, it is good to know about other ways to fix the issue with uneven image lighting.
So, the question is still open...


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 8:34 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
So, what kind of book is it (i.e. lots of text, or mainly pictures... or a combination thereof?).. do you have a sample photo you can post to give an idea of what needs to be done to the image(s)?


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 9:11 am  (#5) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
Zero01 wrote:
So, what kind of book is it (i.e. lots of text, or mainly pictures... or a combination thereof?).. do you have a sample photo you can post to give an idea of what needs to be done to the image(s)?


Yes, I have samples. It is just text without pictures. The gimpchat forum still does not allow me to share external links in my messages, as I am fresh new user, so I will try to trick it somehow. Be creative to make the URL's ;)

Original image: i . imgur . com / fOYOE6L.png
Processed image: i . imgur . com / nk6YrQo.png


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 9:55 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
Is this clear enough?

Image

I got that , again, by using a G'MIC filter, this time 'Film Emulation > Negative [color]'. Maybe that? Of course you could try other combionations of settings and do like I said before (for All Images)


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 10:38 am  (#7) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
Zero01 wrote:
Is this clear enough?
...
I got that , again, by using a G'MIC filter, this time 'Film Emulation > Negative [color]'. Maybe that? Of course you could try other combionations of settings and do like I said before (for All Images)


For sure, I can use 'Film Emulation > Negative [color]' to fix the brightness of images. But as I understand, then I should tune the filter for each image separately, as the illumination of images is not the same. The good thing about algorithm which I described is that it equalize brightness no matter of specific image illumination distribution - the too bright parts get a little darker and vice versa.
I also don't get it how to apply G'MIC filter on a bulk of images (700+) if not manually?


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 11:14 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
The best method IMHO:

- Duplicate the layer
- Apply a heavy gaussian blur, something like 20% of the image size (the lines of text should become indistinguishable).
- Set the top layer to "Divide" mode.

Attachment:
OldDocument-Divide.jpg
OldDocument-Divide.jpg [ 62.78 KiB | Viewed 4420 times ]


Instead of "Divide" you can also use "Grain extract". The paper turns grey instead of white.

_________________
Image


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 11:30 am  (#9) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
ofnuts wrote:
The best method IMHO:

- Duplicate the layer
- Apply a heavy gaussian blur, something like 20% of the image size (the lines of text should become indistinguishable).
- Set the top layer to "Divide" mode.
...
Instead of "Divide" you can also use "Grain extract". The paper turns grey instead of white.


Yes, it is also a quite good method. Now just to see how to do the batch processing :)
I'm playing a bit with the BIMP Plug In and it can do batch with all steps from the algorithm except layer manipulation, or I can't get it how to do it.
Does anybody know hop to duplicate a layer and change the layer mode using BIMP?


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 11:57 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
For a more natural look, you can desaturate the top layer, and reduce the opacity a bit:

Attachment:
OldDocument-Divide+Desaturate+Opacity.jpg
OldDocument-Divide+Desaturate+Opacity.jpg [ 58.38 KiB | Viewed 4411 times ]


You can likely convince some GC denizens to script this for you (including the batching). No, I won't give names, that would be rude :)

_________________
Image


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 12:03 pm  (#11) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
ofnuts wrote:
...
You can likely convince some GC denizens to script this for you (including the batching). No, I won't give names, that would be rude :)


As I am new here I can just hope they will read the topic :tyspin


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 12:51 pm  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
mihvel wrote:
For sure, I can use 'Film Emulation > Negative [color]' to fix the brightness of images. But as I understand, then I should tune the filter for each image separately, as the illumination of images is not the same. The good thing about algorithm which I described is that it equalize brightness no matter of specific image illumination distribution - the too bright parts get a little darker and vice versa.
I also don't get it how to apply G'MIC filter on a bulk of images (700+) if not manually?



Yes, I didn't think of that, of course there is going to be some variation in the lighting from one image to the next and so on, so it'd be difficult to get the right results overall using something like G'MIC (I'm forever extolling it's virtues, but I guess it has it's limitations).
Anyway, good luck finding somebody to script it for you.. if I knew how to I'd try myself! :hehe


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 1:38 pm  (#13) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2418
mihvel wrote:
I'm playing a bit with the BIMP Plug In and it can do batch with all steps from the algorithm except layer manipulation, or I can't get it how to do it.
Does anybody know hop to duplicate a layer and change the layer mode using BIMP?


Using ScanTailor? Could be Linux or Windows. Easier in linux where at least there are a few tools.

Using gmic_gimp and BIMP in linux

David provides (provided, I think it has been updated) a script that BIMP will pick up.

The old one which I use is called gmic_shell.scm where you can enter one or more gmic commands. There is one here: https://github.com/dtschump/gmic/tree/master/src gmic_in_script.scm Never used that one, so this example using the old script.

Picked this example off the internet, https://i.imgur.com/ekNnxMw.jpg obviously all depends on the actual images. (EDIT: Only just seen your muxed imgur ref: but not repeating with new image)

Using gmic_gimp_qt & Gimp 2.8.22 there is a filter Repair scanned document https://i.imgur.com/RGxGAQP.jpg The important bits here are the new image and Very verbose (log file) settings. You need the settings to input into the script.

You are not stuck with one command, choose another filter and same rules apply. Write the settings to the log file. https://i.imgur.com/eesDlYo.jpg

Now for the editing bit: In linux the gmic folder is in ~/.config/gmic Windows is in user/Appdata/Roaming somewhere.

Copy the output from the log file into the script according to the example and save it https://i.imgur.com/F8gFVkm.jpghttps:// ... kNnxMw.jpg

Pop the script into your Gimp profile scripts folder. You can check the action on an open file, the script shows bottom of the Filters menu along with gmic.

but using BIMP: Only one action required, Other Gimp Procedure -> gmic-shell. Add your files, set an output. Very slow, go for a long walk while it works. https://i.imgur.com/JPkpRhX.jpg

Attached the old gmic_shell.scm script as an example

For Gmic see www.gmic.eu


Attachments:
gmic_shell.scm [1.19 KiB]
Downloaded 71 times

_________________
Image
Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 1:56 pm  (#14) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
rich2005 wrote:
mihvel wrote:
I'm playing a bit with the BIMP Plug In and it can do batch with all steps from the algorithm except layer manipulation, or I can't get it how to do it.
Does anybody know hop to duplicate a layer and change the layer mode using BIMP?


Using ScanTailor? Could be Linux or Windows. Easier in linux where at least there are a few tools.

Using gmic_gimp and BIMP in linux

David provides (provided, I think it has been updated) a script that BIMP will pick up.

The old one which I use is called gmic_shell.scm where you can enter one or more gmic commands. There is one here: https://github.com/dtschump/gmic/tree/master/src gmic_in_script.scm Never used that one, so this example using the old script.

Picked this example off the internet, https://i.imgur.com/ekNnxMw.jpg obviously all depends on the actual images. (EDIT: Only just seen your muxed imgur ref: but not repeating with new image)

Using gmic_gimp_qt & Gimp 2.8.22 there is a filter Repair scanned document https://i.imgur.com/RGxGAQP.jpg The important bits here are the new image and Very verbose (log file) settings. You need the settings to input into the script.

You are not stuck with one command, choose another filter and same rules apply. Write the settings to the log file. https://i.imgur.com/eesDlYo.jpg

Now for the editing bit: In linux the gmic folder is in ~/.config/gmic Windows is in user/Appdata/Roaming somewhere.

Copy the output from the log file into the script according to the example and save it https://i.imgur.com/F8gFVkm.jpghttps:// ... kNnxMw.jpg

Pop the script into your Gimp profile scripts folder. You can check the action on an open file, the script shows bottom of the Filters menu along with gmic.

but using BIMP: Only one action required, Other Gimp Procedure -> gmic-shell. Add your files, set an output. Very slow, go for a long walk while it works. https://i.imgur.com/JPkpRhX.jpg

Attached the old gmic_shell.scm script as an example

For Gmic see http://www.gmic.eu


Huh, it will take some time to process this. Forget about ScanTailor, it is an application irrelevant for this topic. I'm using GIMP on Windows so I need to adjust some steps in your guide.


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 2:28 pm  (#15) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2418
mihvel wrote:
Huh, it will take some time to process this. Forget about ScanTailor, it is an application irrelevant for this topic. I'm using GIMP on Windows so I need to adjust some steps in your guide.


You are the one who mentioned scantailor...and also BIMP Just offering a possible solution.

Quote:
..For that purpose I'm using ScanTailor program...


Attached a slightly tweaked script to suit your scan. Is that the best you can do? IMHO too small.

Anyway to check the script, You will need gmic intalled. Running on your example

Attachment:
compare.jpg
compare.jpg [ 188.92 KiB | Viewed 1282 times ]


For lots of images use it with BIMP as previous post.


Attachments:
gmic_shell.scm [1.2 KiB]
Downloaded 74 times

_________________
Image
Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 2:50 pm  (#16) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
rich2005 wrote:
You are the one who mentioned scantailor...and also BIMP Just offering a possible solution.

Yes I did mention ScanTailor in a broader description of my problem. But I understood it was confusing reference for you, so I just wanted to say that is irrelevant for the solution I'm looking for.

rich2005 wrote:
Attached a slightly tweaked script to suit your scan. Is that the best you can do? IMHO too small.

I don't understand :?... Did I wrote something wrong?

rich2005 wrote:
Anyway to check the script, You will need gmic intalled. Running on your example
...
For lots of images use it with BIMP as previous post.


Yes, I installed both, BIMP and G'MIC. Actually, I can run sequence of G'MIC filters on multiple images directly from BIMP, so I do not understand why do I need gmic_shell.scm?

Thanks for your help!


Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Sun Nov 05, 2017 6:21 pm  (#17) 
Offline
GimpChat Member

Joined: Nov 04, 2017
Posts: 9
Well, I did it :jumpclap . Based on script sent by rich2005 I created my own solution that performs sequence of the algorithm from the beginning of this topic (duplicate layer/gaussian blur/invert color/desaturate color/layer mode overlay). G'MIC is not used so I changed the script name to my-img-shell. It is in the attachment.
For batch processing I used BIMP plugin and called my-img-shell script from it.

Thanks to all of you guys for your help!


Attachments:
my_img_shell.scm [1.36 KiB]
Downloaded 105 times
Top
 Post subject: Re: Batch script for image brightness equalization?
PostPosted: Mon Nov 06, 2017 1:01 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
Impressive, well done!


Top
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) converting 32 bit images to 8 bit using batch script

5

No new posts Attachment(s) Seeking Help with First Multi-File Batch Script

9

No new posts Attachment(s) Batch export all opened images script for GIMP [Update]

13

No new posts Attachment(s) Matching my Phone Camera's 'Brightness' Adjustment

1

No new posts GEGL filter to Extract, Recolor and Blur a Brightness Channel

1



* Login  



Powered by phpBB3 © phpBB Group