User-Defined Kernel Filtering Code Snippet¶
This code snippet shows how to apply a convolution operation based on a user-defined kernel.
C++¶
#include <eVision/EasyImage/EasyImage.h>
using namespace eVision;
// Images constructor
EImageBW8 srcImage;
EImageBW8 dstImage;
// ...
// Create and define a user-defined kernel
// (Frei-Chen row gradient, positive only)
EKernel kernel;
kernel.SetKernelData(0.2929f, 0, -0.2929f,
0.4142f, 0, -0.4142f,
0.2929f, 0, -0.2929f);
// Source and destination images must have the same size
dstImage.SetSize(&srcImage);
// Apply the convolution kernel
EasyImage::ConvolKernel(&srcImage, &dstImage, &kernel);
C#¶
using eVision;
// Images constructor
EImageBW8 srcImage = new EImageBW8();
EImageBW8 dstImage = new EImageBW8();
// ...
// Create and define a user-defined kernel
// (Frei-Chen row gradient, positive only)
EKernel kernel = new EKernel();
kernel.SetKernelData(0.2929f, 0, -0.2929f,
0.4142f, 0, -0.4142f,
0.2929f, 0, -0.2929f);
// Source and destination images must have the same size
dstImage.SetSize(srcImage);
// Apply the convolution kernel
EasyImage.ConvolKernel(srcImage, dstImage, kernel);
Python¶
from eVision import EImageBW8, EKernel, EasyImage
# Images constructor
src_image = EImageBW8()
dst_image = EImageBW8()
# ...
# Create and define a user-defined kernel
# (Frei-Chen row gradient, positive only)
kernel = EKernel()
kernel.SetKernelData(0.2929, 0, -0.2929,
0.4142, 0, -0.4142,
0.2929, 0, -0.2929)
# Source and destination images must have the same size
dst_image.SetSize(src_image)
# Apply the convolution kernel
EasyImage.ConvolKernel(src_image, dst_image, kernel)