OpenCV image edge extraction (2) - Sobel operator principle and OpenCV API usage (C#)

Insert image description here

Principle : When the pixel transition is large at the edge of the image, the first derivative of the image is obtained. The maximum derivative value is the location of the edge pixel.
Insert image description here

Related APIs:

public static void Sobel(InputArray src, OutputArray dst, MatType ddepth, int xorder, int yorder, int ksize = 3, double scale = 1, double delta = 0, BorderTypes borderType = BorderTypes.Reflect101);

Parameter description:
Insert image description here
When dx=0,dy=1, the y-direction contour is clearly preserved;
when dx=1,dy=0, the x-direction contour is clearly preserved;

if (fileDialog.ShowDialog() == DialogResult.OK)
   {
    
    

       inputMat = Cv2.ImRead(picFile, ImreadModes.Grayscale);
       outMat = new Mat(new Size(inputMat.Cols, inputMat.Rows), inputMat.Type());
       Cv2.Sobel(inputMat, outMat, MatType.CV_8UC1, 1, 1,5);
       picBox_Display.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(inputMat);
       picBox_After.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(outMat);
   }

Insert image description here

Additional notes:
The OpenCV library used in .NET in this case is OpenCvSharp4

OpenCv library for .NET environment

Guess you like

Origin blog.csdn.net/weixin_40671962/article/details/127059855