PDL::Image2D is a Perl module that contains miscellaneous 2D image processing functions.
For large kernels, using a FFT routine, such as fftconvolve() in PDL::FFT, will be quicker.
$new = conv2d $old, $kernel, {OPTIONS}
$smoothed = conv2d $image, ones(3,3), {Boundary => Reflect}
Boundary - controls what values are assumed for the image when kernel
crosses its edge:
=> Default - periodic boundary conditions
(i.e. wrap around axis)
=> Reflect - reflect at boundary
=> Truncate - truncate at boundary
EOD BadDoc => 'Unlike the FFT routines, conv2d is able to process bad values.', HandleBad => 1, Pars => 'a(m,n); kern(p,q); [o]b(m,n);', OtherPars => 'int opt;', PMCode => '
sub PDL::conv2d { my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH'; die 'Usage: conv2d( a(m,n), kern(p,q), [o]b(m,n), {Options} )' if $#_2; my($a,$kern) = @_; my $c = $#_ == 2 ? $_[2] : $a->nullcreate; &PDL::_conv2d_int($a,$kern,$c, (!(defined $opt && exists $$opt{Boundary}))?0: (($$opt{Boundary} eq "Reflect") + 2*($$opt{Boundary} eq "Truncate"))); return $c; }
', Code => init_vars( { vars => 'PDL_Double tmp;' } ) . init_map("i") . init_map("j") . ' threadloop %{ for(j=0; jj2) * $kern(p=>i1,q=>j1);
} /* for: i1 */
} /* if: j2 >= 0 */
} /* for: j1 */
$b(m=>i,n=>j) = tmp;
} /* for: i */
} /* for: j */
%}
free(mapj+1-q_size); free(mapi+1-p_size);',
BadCode =>
init_vars( { vars => 'PDL_Double tmp; int flag;' } ) .
init_map("i") .
init_map("j") .
'
threadloop %{
for(j=0; jj2)) && $ISGOOD(kern(p=>i1,q=>j1)) ) {
tmp += $a(m=>i2,n=>j2) * $kern(p=>i1,q=>j1);
flag = 1;
} /* if: good */
} /* if: i2 >= 0 */
} /* for: i1 */
} /* if: j2 >= 0 */
} /* for: j1 */
if ( flag ) { $b(m=>i,n=>j) = tmp; }
else { $SETBAD(b(m=>i,n=>j)); }
} /* for: i */
} /* for: j */
%}
free(mapj+1-q_size); free(mapi+1-p_size);',
Requirements:
· Perl
Product's homepage
Requirements:
· Perl