拉普拉斯(Laplacian)操作也是一个派生的操作,用来找出图像中的边缘。 这是一个二阶导数掩模。 在这个隐藏中,我们有两个进一步的分类,一个是正拉普拉斯操作,另一个是负拉普拉斯操作。
与其他算子不同,拉普拉斯并没有在任何特定方向上取出边缘,而是在后续分类中取出边缘。
可以使用imgproc
类的Laplacian()
方法对图像执行拉普拉斯变换操作,以下是此方法的语法。
Laplacian(src, dst, ddepth)
该方法接受以下参数 -
Mat
类的对象。Mat
类的对象。示例
以下程序演示如何对给定图像执行拉普拉斯变换操作。
package com.zyiz.transformation; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class LaplacianTest { public static void main(String args[]) { // Loading the OpenCV core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //Reading the Image from the file and storing it in to a Matrix object String file ="F:/worksp/opencv/images/sample3.jpg"; Mat src = Imgcodecs.imread(file); // Creating an empty matrix to store the result Mat dst = new Mat(); // Applying GaussianBlur on the Image Imgproc.Laplacian(src, dst, 10); // Writing the image Imgcodecs.imwrite("F:/worksp/opencv/images/sample3laplacian.jpg", dst); System.out.println("Image Processed"); } }
假定以下是上述程序中指定的输入图像sample3.jpg
。
执行上面示例代码,得到以下结果 -