Code: Select all
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
Code: Select all
my $y = int (($height / $height_incr) - .5);
my $dy = 0;
until (($dy + $y) > $height) {
my $dx = 0;
my @values;
until ($dx >= ($width - $width_incr)) {
my $region = "${width_incr}x$y+$dx+$dy";
my $cmd = "convert -crop $region temp.tif -format \"%[fx:100*mean]\" info:";
open (INFO, "$cmd |");
my $info = <INFO>;
chomp ($info);
close (INFO);
push @values, $info;
$dx += $width_incr;
}
$dy += $y;
}
The problem for me is the crop. I tried using -region so I could change that repeatedly in one command but Imagemagick seems to ignore it here and gives me the percentage of white in the whole image. So I have to re-read and re-crop the image over 600 times per page. So any ideas how to speed the process up?
I have PerlMagick installed and I'm thinking there might be a more efficient way with that, read the image once into memory and operate repeatedly on that. Is there a way to crop a region in PerlMagick to get the info I want, then undo the crop and recrop at the new coordinates? I see in the documentation that omitting the x and y offsets for the crop command will generate a series of images. That sounds like it could be more efficient. Can PerlMagick do this and store the segments in an array or something so I can loop through them all? Or is there a simple ImageMagick command that I've overlooked?
Arvin