Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Harnessing the Perl Goodness of The Gimp in the Name of Biology

by Arguile (Hermit)
on Jun 09, 2003 at 06:23 UTC ( [id://264257]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: pixel counting on a fouling panel
in thread pixel counting

As requested in CB, some clarification...

From what you’ve said you’ll be hand drawing outlines of what you believe to be the extent of each species boundry; even if another species happens to be overgrowing that boundry to some extent. In this case you’ll be guessing the exact extent and copying that whole area into a new image.

What I propose is creating a layer or channel** for each species in the image. So for each species:

  1. Create a layer or channel
  2. Turn on their layer (to around 50% transparency so you can see the image underneath)
  3. Use a paintbrush to mask the areas you think they exist in, even if partially covered by another species.
  4. Turn off the layer.

This will essentially give you a one bit mask that represents the living area of each species. The layers can all overlap without interfering with each other. In addition all the data is stored in one file, easy to keep track of or change.

This could also work very well for quick visual surveys if you wanted to get fancy. Assign each species-layer a colour and then turn the ones of interest on with a high transparency. You’ll see a montage of interacting colour representative of that species living areas and their overlaps.

Anyways, enough talk. On to some code!

use Gimp qw(:auto); use Gimp::Fu; # ... my @species = qw( mussels squid octocerata ); # Our species of intere +st. # Create a layer for each species (labelled for that species) and add +it to # the image. foreach my $specie ( @species ) { my $layer = gimp_layer_new( $img, $w, $h, RGB, $specie, 50, NORMAL +_MODE); gimp_image_add_layer($layer, -1); } # ...

Adding a zillion layers (one for each specie) to each image would be boring manual work (colouring will be boring enough), so in the above partial snippet we let a Gimp script do that for us. In production you’d probably pull this from a file or database. Anything else you'd normally do to preprocess the image could be done here as well, for example autolevels or auto contrast.

It’s late, so I think I’ll stop here. For now I’ll leave you with some reference material to look over.

See Also:


** Layers and channels are different, which you use will depend on exactly what you want to do with it. If all you need is a one bit mask then channels would be your best choice. For simplicity sake I’ll refer to the choice as layers throughout the post.

*** Spiffy title eh? :)

Replies are listed 'Best First'.
Re: Harnessing the Perl Goodness of The Gimp in the Name of Biology
by redbeard (Beadle) on Jun 10, 2003 at 23:54 UTC

    Fantastic, and thanks so much for the reference material! THis method may well work, esp if I can then incorporate a way to count pixels per layer into the script and then dump the output into a file (read in the current species mentioned, add any new species from this particular image, reoutput the old data with 0's in corresponding new species, then output a line of the new data).

    Just gotta brush up on my Gimp-perl!

    Although I may still use the cut-into-seperate-images method, as I'm thinking of spreading this script around to some other folk I know who do similar analyses, and they're not so gimp-savy, although they're all OSX users.

    If only I could make this a photoshop plugin as well...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://264257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-03-29 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found