I would like to sharp an image by performing CvInvoke.Filter2d with a sharpening kernel: {[-1,-1,-1],[-1, 9,-1],[-1,-1,-1]}
How do I can define this kernel in EMGU under C#?
I'm using EMGU version 4.3.0.3890
This is my code:
// Load image
Image<Bgr, Byte> img = null;
img = new Image<Bgr, byte>(@"D:\Sample.png");
// Convert the image to grayscale
Image<Gray, float> gray = img.Convert<Gray, float>()
.ThresholdBinary(new Gray(150), new Gray(255));
// Add use of Filter2D here
// Load image
Image<Bgr, byte> img = new Image<Bgr, byte>(@"path/img.jpg");
// Convert the image to grayscale
Image<Gray, byte> gray = img.Convert<Gray, byte>().ThresholdBinary(new Gray(150), new Gray(255));
// Add use of Filter2D here
CvInvoke.Imshow("GrayImage", gray);
float[,] matrix = new float[3, 3] {
{ 1, 1, 1 },
{ 1, -9, 1},
{ 1, 1, 1 }
};
ConvolutionKernelF matrixKernel = new ConvolutionKernelF(matrix);
var dst = new Mat(gray.Size, DepthType.Cv8U, 1);
CvInvoke.Filter2D(gray, dst, matrixKernel, new Point(0, 0));
CvInvoke.Imshow("FiltredImage", dst);
CvInvoke.WaitKey(0);
PS:
Preferably you have to use Mat and Matrix (if you need to access the pixels) and not image. --> source: https://www.emgu.com/wiki/index.php/Working_with_Images
By converting to gray level, it is necessary to take the type byte and not float
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With