The idea is very simple. You increase(decrease) the rgb values to adjust brightness, and you adjust the contrast with +- intensity.
Experiment on 1 first to get the best setting, then run it in a whole dir full of images. If you keep the $r $g $b values identical, the brightness change will be uniform, otherwise you will be adjusting "tint" as well.
#!/usr/bin/perl use warnings; use strict; use Imager; use File::Basename; # Usage: "scriptname red blue green contrast" # example: " script 2.0 2.0 0.5 2.0" # 1.0 is "no change", values less than 1 reduce my ($r,$g,$b,$c) = @ARGV; $r = $r || 1; $g = $g || 1; $b = $b || 1; $c = $c || 1; umask 0022; my @pics= <*.jpg *.gif *.png>; my @exts = qw(.jpg .gif .png); my $img = Imager->new(); my @redmap = map { int( $r * $_) } 0..255; my @greenmap = map { int( $g * $_) } 0..255; my @bluemap = map { int( $b * $_) } 0..255; foreach my $file (@pics){ my ($basename,$path,$suffix) = fileparse($file,@exts); $img->open(file=>$file) or die $img->errstr(); my $newimg = $img->copy(); $newimg->map( red=>\@redmap, green=>\@greenmap, blue=>\@bluemap ); $newimg->filter(type=>'contrast', intensity=> $c); $newimg->write(file=>"$basename-b$suffix" ); }
In reply to batch rgb brightness and contrast adjustment by zentara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |