Nice with the IPython notebooks, Zaki.

Here is a sample code showing processingusing color in addition to
intensity.
In this type of processing, the real workcomes in cleaning up the data,
removing
flaws and irregularities,...

# Color segmentation and processing for chromatography
> # An example of using PDL for image processing
> use PDL;
> use PDL::NiceSlice;
> use PDL::IO::Pic;
> use Time::HiRes qw(sleep);
> use PDL::Graphics2D;
> use PDL::Image2D;
>
> # Read in image data, mv() used to put pixel axis in dim(0)
> $tlc = rim('TLC_arg.jpg')->mv(-1,0);
> imag2d $tlc, 'TLC', 0.25;
>
> # Select background pixels based on the white part of the
> # image and calculate the average color...
> #
> # Convert RGB to greyscale by calculated the average pixel value
> $tlc_g = $tlc->float->average;
>
> # Background is the top 50% pixels
> $back_mask = ($tlc_g > $tlc_g->pct(0.5));
> imag2d $back_mask, 'background mask', 0.25;
>
> # Average background RGB value
> $background = $tlc->mv(0,-1)->whereND($back_mask);
> $b_rgb = $background->float->average;
>
> # Compute color direction vector
> $b_color = $b_rgb->norm;
>
> # Calculate the color direction for each pixel
> $tlc_unit = $tlc->float->norm;
> imag2d $tlc_unit, 'TLC unit', 0.25;
>
> # We calculate the deviation from the background direction
> $tlc_cos = $tlc_unit->inner($b_color);
>
> # Switch to sin which is proportional to angle
> $tlc_sin = sqrt(1-$tlc_cos);
> $tlc_sin /= $tlc_sin->max;
>
> # Background is at 0 and color differences are positive
> imag2d $tlc_sin, 'tlc color angle', 0.25;
>
> # Look at hist values to pick color delta threshhold to make mask
> print cat($tlc_sin->hist(0,1,0.05))->mv(0,1), "\n";
> $spot_mask = ($tlc_sin>0.1);  # 10% looks good
> imag2d $spot_mask->float, 'spot mask', 0.25;
>
> # Calculate connected clusters in the mask image
> $cc8 = $spot_mask->float->cc8compt;
> imag2d $cc8/$cc8->max, 'cc8 big', 0.25;
>
> # Calculate cluster sizes from segement index values
> ($num,$label) = $cc8->flat->qsort->rle;
> $maxind = which($num>0)->max;
>
> # Chop off the trailing zeros from rle result
> $num = $num(0:$maxind);
> $label = $label(0:$maxind);
>
> # Clean up clusters by removing below a certain size
> # Take a look at the sizes to find a cut point
> print cat($num,$label)->mv(0,1)->qsortvec, "\n";
>
> # loop over cluster values and clear if size < 100
> foreach my $ind ( $label->where($num < 100)->list ) {  $cc8->where($cc8 ==
> $ind) .= 0 };
>
> # More segementation could use hue variation in addition to difference
> from background
> $tlc_cross = $tlc_unit->crossp($b_color);
> $xxx = $tlc_cross / ($tlc_cross->stats)[1];
> $xxx = $xxx->rint->clip(-1,1);
> imag2d $xxx/2+0.5, 'binary box', 0.25;
>
> # look at which pixels correspond to the uniq triplet values from $xxx
> # such a [1,0,0], [1,1,0], ...
> $plane = $xxx->norm->(:,*1)->inner($xxx->uniqvec->norm);
> $plane->where($plane <  0.9999) .= 0;
> $plane->where($plane >= 0.9999) .= 1;
>
> # loop and show for now
> $win = imag2d $plane((0)), 'plane', 0.25;
> $loopmod = $plane->dim(0);
> foreach my $level ( 0..1000 ) { my $ind = $level%$loopmod; imag2d_update
> $win, $plane(($ind)); sleep 0.5; }
>
>
--Chris

On Thu, Apr 23, 2015 at 4:16 PM, Demian Riccardi <[email protected]>
wrote:

> holy smokes!
>
> > On Apr 23, 2015, at 4:12 PM, Zakariyya Mughal <[email protected]>
> wrote:
> >
> > On 2015-04-23 at 11:06:38 -0600, Derek Lamb wrote:
> >>
> >>> On Apr 23, 2015, at 9:34 AM, Zakariyya Mughal <[email protected]>
> wrote:
> >>>
> >>> Ignore my e-mail about using clustering algorithms... Craig's e-mail
> >>> reminded my that you can do blob extraction in one-pass using
> >>> <
> https://en.wikipedia.org/wiki/Connected-component_labeling#One-pass_version
> >.
> >>> There's some C code at <
> http://www-sop.inria.fr/members/Gregoire.Malandain/segment/connexe.html>,
> >>> but I haven't used it.
> >>>
> >>> Cheer,
> >>> - Zaki Mughal
> >>
> >> Even better, PDL already has connected-componenet labeling!  See
> cc8compt, cc4compt, and ccNcompt.
> >>
> >> http://pdl.perl.org/?docs=Image2D&title=PDL::Image2D#cc8compt
> >
> > Thanks!
> >
> > I gave it a go at <
> http://nbviewer.ipython.org/gist/zmughal/fae2a5901d59504b56e1/Thin-layer-chromatography-analysis.ipynb
> >.
> >
> > I'm going to have to compare this with the MATLAB equivalent at some
> > point to see if PDL's version can be made simpler.
> >
> > Cheers,
> > - Zaki Mughal
> >
> >>
> >> Derek
> >
> >
> ------------------------------------------------------------------------------
> > BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
> > Develop your own process in accordance with the BPMN 2 standard
> > Learn Process modeling best practices with Bonita BPM through live
> exercises
> > http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual-
> event?utm_
> > source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
> > _______________________________________________
> > pdl-general mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/pdl-general
>
>
>
> ------------------------------------------------------------------------------
> BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
> Develop your own process in accordance with the BPMN 2 standard
> Learn Process modeling best practices with Bonita BPM through live
> exercises
> http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual-
> event?utm_
> source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
>
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to