// Program to demonstrate use of IPConvSymC, a templated linear symmetric // convolution filter. #include "amma/Image/IPConvSym.hh" #include "amma/Image/IPGaussConv.hh" #include "amma/DP/ComposeSE.hh" // only needed for 2nd filter method #include "amma/SDFunct1.hh" // only needed for the predefined Binomial example int main () { using namespace IPSpatFilterN; NumImageC in(6,6); in.Fill(1.0); NumImageC out; SArray1dC coeff(3); coeff[0] = 6; coeff[1] = 4; coeff[2] = 1; // i.e. 5-tap filter with values 1,4,6,4,1 // Basic method to apply vertical filter to image, with default erode option out = IPConvSymC(coeff,Vertical).Apply(in); cout << out << "\n\n"; // The same method, but more compact, for a horizontal filter, expanding // output to include all non-zero information. The technique extends the i/p // image with black pixels. cout << (IPConvSymC(coeff,Horizontal,Expand,PadBlack).Apply(in)) << "\n\n"; // Alternative method using DPComposeSE stream, preserving original input // image size. The technique again extends the i/p image with black pixels, // and then "renormalises" the pixels near the border to preserve the // d.c. level. using namespace DPComposeSE; in >> IPConvSymC(coeff,TwoD,Original) >> out; cout << out << "\n\n"; // You could create the mask from one of the SDFunction1dC functions, // e.g. Binomial(). But you must use an odd size, and select just the // right-hand half: IntT size=5; //N.B. Funny initialisation using static member function. SDFunction1dC mask_two_sided(SDFunction1dC::Binomial(size,true)); SArray1dC mask((size+1)/2); for (UIntT i=0; i> IPConvSymC(mask,Horizontal,Expand,PadBlack) >> out; cout << out << "\n\n"; // But much better, for the Binomial example, you could use IPGaussConvolveC // to do all this for you, & you should get the same answer: in >> IPGaussConvolveC(5,Horizontal,Expand,PadBlack) >> out; cout << out << "\n\n"; }