App-PLab

 view release on metacpan or  search on metacpan

bin/MorphometryI  view on Meta::CPAN


   if ( open F, "> $xmlname") {
      my $waitPtr = $::application-> pointer;
      $::application-> pointer( cr::Wait);
      $w-> sb_text("saving $xmlname");
      $w-> win_validate(1);
      $w-> win_syncrecdata;
      my $image = $w-> IV-> image;
      if ( $w->{ini}->{CalcBrightness} && $w->{ini}->{EqualBrightness}) {
         # subtracting low frequencies
         $w-> sb_text("Equalizing background ...");
         my $i1 = Prima::IPA::Global::butterworth( $image, 
            low        => 1,
            homomorph  => 0,
            power      => 2,
            cutoff     => 20,
            boost      => 0.7,
            spatial    => 1,
            lowquality => 1,
         );
         $i1-> type( $image-> type);

bin/MorphometryI  view on Meta::CPAN

   my $index = 0;
   my $statCount = 4;
   my @resName;


   for my $xmlname ( @res) {
      my ( $bN, $bSum, @hist);
      push( @resName, "$xmlname : ");
      my $state = $w-> win_xmlload( $xmlname, onObject => sub {
         my ( $attrs, $n0, $n1) = @_;
         # collect sum of backgrounds
         if ( $attrs->{type} eq $n0 || $attrs->{type} eq $n1) {
            my $stref = $attrs->{type} eq $n0 ? \%dataFore : \%dataBack;
            if ( 3 == grep {exists $attrs->{$_}} qw{brightnessN brightnessSum brightnessSum2}) {
               $stref->{brightness} = [(0) x $statCount] unless defined $stref->{brightness};
               $stref->{brightness}-> [0] += $attrs->{brightnessN};
               $stref->{brightness}-> [1] += $attrs->{brightnessSum};
               $stref->{brightness}-> [2] += $attrs->{brightnessSum2};
               # XXX warning - bogus data for backgrounds !!
               $stref->{brightness}-> [$statCount + $index] = $attrs->{brightnessSum} / $attrs->{brightnessN};
               # collect local sum of background data
               if ( $attrs->{type} eq $n1) {
                  $bN   += $attrs->{brightnessN};
                  $bSum += $attrs->{brightnessSum};
               }
            }
            return if $attrs->{type} eq $n1; # no background relevant data further

            push @dataHist, exists( $attrs->{histogram}) ? [split(' ', $attrs->{histogram})] : undef;
            push( @hist, $dataHist[-1]) if $dataHist[-1]; # push the histogram ref for the post-processing
            
            if ( exists $attrs->{area} && exists $attrs->{harea}) {
               my $nh = 0;
               my $tharea = 0;
               my $minArea = $attrs->{area} * $w->{ini}->{HolesPercent} / 100;
               my @holz = split ' ', $attrs->{harea};
               for my $harea ( @holz) {

bin/MorphometryI  view on Meta::CPAN

               $dataCommon{$_}-> [1] += $attrs->{$_};
               $dataCommon{$_}-> [2] += $attrs->{$_} * $attrs->{$_};
               $dataCommon{$_}-> [$statCount + $index] = $attrs->{$_};
            }
            $index++;
            $resName[-1] .= "$index ";
         }
      } 
      );
      return unless $state;
      # subtract backgrounds
      if ( vec( $dres, ocq::Equalize, 1)) {
          if (!$bN && @hist) {
             # noting to subtract, nulling histograms
             splice( @dataHist, -(@hist), (@hist), (undef)x scalar(@hist));
          } elsif ( @hist) {
             my $b = int($bSum / $bN); # average brightness for background(s) within file
             if ( $b > 255 || $b < 0) {
                $@ = "Somehow the average brightness is not in range of 0..255.\n";
                $w-> win_xmlerror( $xmlname);
             }   
             for ( @hist) { # shift array left $b times
                splice( @$_, 0, 0, (0)x(255-$b)); # add space for negative brightnesses
                push( @$_, (0)x($b)); 
             }
          }   
      }

bin/MorphometryI  view on Meta::CPAN

   my $tm = localtime;
   $texts = <<HR;
Statistics morphology data
Calculated on $tm
HR
   if ( vec( $dres, ocq::Files, 1)) {
      my $howmany = ( scalar @resName > 1) ? "s were" : " was";
      $texts .= "The following file$howmany used for data gathering:\n";
      $texts .= "   $_\n" for @resName;
   }
   $texts .= sprintf("Average background brightness: %.7g +/- %.7g (averaged by %d pixels)\n",
      $dataBack{brightness}->[1],
      $dataBack{brightness}->[3],
      $dataBack{brightness}->[0],
   ) if defined $dataBack{brightness};
   my ( $title, $meta1, $meta2) = ( "$texts\n", '', '');

   if ( vec( $dres, ocq::Basics, 1)) 
   {
      {
         (my $xhdr = $hdr) =~ s/\s\|//g;

lib/App/PLab/MorphometryI.pod  view on Meta::CPAN

=item Undo

There are provided three of undo commands. As far as mouse movement is recorded and set of straight lines,
the first undo, "Undo drawing", erases last line drawn. <br>
Second step is "Group undo", which erases the whole contour. Both of these operation are irreversible,
so third step, "Undo dialog" bring an dialog that masters drawings in more flexible way.
Command "Clear all drwaings" clear all contours, respectively.

=back

=head2 Objects and background

Program is capable of collecting information of two different kinds of contours, namely
I<objects> and I<backgrounds>. Their difference is only when calculations take place,
in visual representaions they differs only in the color drawn. Default object color is green, background - 
yellow. It could be changed in Preferences, Appearance bookmark.

Before program calculates data, it has to validate the contours drawn in some way. This is accomplished
using image-processign algorithm, that leaves only closed contours. This function activated either by
"Edit/Validate contours" command or implicitly when closing and image.

=for podview <img src="mIc1.gif">

=for podview <img src="mIc2.gif">

lib/App/PLab/MorphometryI.pod  view on Meta::CPAN

The program can collect more information about the objects, but since it requires
quite a lot time to compute, these features are turned off by default.
The "Calculation" page in preferences dialog contains settings of these calculations.
The following topics controls the program behavior when the .xml file is written on disk.

=over

=item Calculate brigthness

If on, the summary brightnesses and the brightness histogram are calculated for
each object. For the backgrounds, however, histogram is not calculated.
The calculation takes significant time and depends on number of objects.

=item Equalize brightness

Can only be on if "Calculate brightness" is on also. Before the brightess
calculations are performed, the image is subject to equalization procedure,
used to make the background of the scene equally illuminated. The calculation
time is very large, but it's not dependant of objects amount.

=item Convex hull derived parameters

If on, perform calculation of set of parameters for every object, which are:
for object: width, length, length/width, and breadth; for convex: area, width, perimeter, form factor,
xcentroid, ycentroid, fxcentroid, fycentroid, object length/convex width, and spreading index.
calculation time is small and depends of number of objects. Cannot be turned off while
"Process index/domain" switch is on.



( run in 3.860 seconds using v1.01-cache-2.11-cpan-f56aa216473 )