Opencv-laplacian-transformation

提供:Dev Guides
移動先:案内検索

OpenCV-ラプラシアン変換

ラプラシアン演算子は、画像内のエッジを見つけるために使用される微分演算子でもあります。 これは二次微分マスクです。 このマスクには、さらに2つの分類があります。1つは正のラプラシアン演算子で、もう1つは負のラプラシアン演算子です。

他の演算子とは異なり、ラプラシアンは特定の方向のエッジを取り出しませんでしたが、次の分類ではエッジを取り出します。

  • 内向きエッジ

  • 外向きエッジ

    *imgproc* クラスの* Laplacian()*メソッドを使用して、画像に対して* 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 が次のものであると仮定します。

ラプラシアン入力

出力

プログラムを実行すると、次の出力が得られます-

Image Processed

指定したパスを開くと、次のように出力画像を観察できます-

ラプラシアン出力