Check my module https://metacpan.org/pod/PDL::Apply which tries to implement something pretty close to your problem although it is not as efficient as C implementation.

--
kmx

On 1.3.2016 17:06, Pakhomov Yury wrote:
Hello all!

How to write PDL efficient code for computing the moving average or
moving median?

For example, I want to use the median filter width of 33 pixels for data:

$x=sequence(1000);
$y=sin($x/10)+random($x)/10;

For data of little size I can create new piddle size of (33,nelem($y))
where each row contains a portion of data size of 33 which then I
include in "medover":

$med=&medianPDL($y,33);

sub medianPDL{
   my $pdl=shift;
   my $win=shift;
   my $tmp=zeroes($win,nelem($pdl));
   my $inds=yvals($tmp)-int($win/2)+xvals($tmp);
   my $a=$inds->minimum;
   $a->where($a>=0).=0;
   $inds-=$a->dummy(0,$win);
   my $b=$inds->maximum-$tmp->getdim(1)+1;
   $b->where($b<0).=0;
   $inds-=$b->dummy(0,$win);

   return $pdl->index($inds)->medover;
}

________________________________

May be exists a more efficient way to compute the moving average or
moving median?

Yury


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general


------------------------------------------------------------------------------
_______________________________________________
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to