in reply to pixel counting on a fouling panel
in thread pixel counting
This is untested; just going from memory and a quick look at the Image::Magick API Reference. Basically it should read in the image, figure out which colour is transparent, then loop through every pixel and increment a counter when the pixel isn’t transparent. Again, it’s untested. I’m unsure if the pixel index starts at 1 (as I used) or 0. I’m also not totally sure on the $image->Get('transparent') call -- read the API for the exact method -- it’s been a while since I've used it. This should give you a good jumping off point though.
use Image::Magick; my $image = new Image::Magick; $image->Read('foo.png'); my $count; # The number of non-tra +nsparent pixels. my $transparent = $image->Get('transparent'); # Index of the transpar +ent colour. my $height = $image->Get('height'); # Image height. my $width = $image->Get('width'); # Image width. for my $x ( 1 .. $height ) { for my $y ( 1 .. $width ) { $count++ if $image->Get("pixel[$x,$y]") != $transparent; } }
If I get what you're trying to do, it might be beneficial to store each species as a mask. If you save it as a black and white bitmap counting becomes really fast, since you can read the file as one long binary string and just count the 1’s.
Another possibility (again I’m assuming you're generating these masks by hand) is to use a format that allows multiple layers. Storing the image as a photoshop PSD or something similar would allow you to keep all the masks as named channels or layers. The Gimp might be a great tool here as it allows Perl extensions and has said layers. This way the masks stay embedded right in the original image for easy archiving, and you could even store the result of those counts in the image comments. With a little Perl magic, Gimp could become a biology workdesk :).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: pixel counting on a fouling panel
by redbeard (Beadle) on Jun 09, 2003 at 03:40 UTC | |
by Arguile (Hermit) on Jun 09, 2003 at 06:23 UTC | |
by redbeard (Beadle) on Jun 10, 2003 at 23:54 UTC |