OpenCV - 拉普拉斯變換



拉普拉斯運算元也是一種微分運算元,用於查詢影像中的邊緣。它是一個二階導數掩膜。在這個掩膜中,我們還有兩種進一步的分類,一種是正拉普拉斯運算元,另一種是負拉普拉斯運算元。

與其他運算元不同,拉普拉斯運算元不會以任何特定方向提取邊緣,而是根據以下分類提取邊緣。

  • 內邊緣
  • 外邊緣

您可以使用 **imgproc** 類的 **Laplacian()** 方法對影像執行 **拉普拉斯變換** 操作,以下是此方法的語法。

Laplacian(src, dst, ddepth)

此方法接受以下引數:

  • **src** - 一個表示此操作的源(輸入影像)的 **Mat** 物件。

  • **dst** - 一個表示此操作的目標(輸出影像)的 **Mat** 物件。

  • **ddepth** - 一個整型變數,表示目標影像的深度。

示例

以下程式演示瞭如何對給定影像執行拉普拉斯變換操作。

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 ="E:/OpenCV/chap18/laplacian_input.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("E:/OpenCV/chap18/laplacian.jpg", dst);

      System.out.println("Image Processed");
   }
}

假設以上程式中指定了以下輸入影像 **laplacian_input.jpg**。

Laplacian Input

輸出

執行程式後,您將獲得以下輸出:

Image Processed

如果您開啟指定的路徑,您可以觀察到輸出影像如下:

Laplacian Output
廣告
© . All rights reserved.