การเปลี่ยนรูปแบบ Laplacian บนรูปภาพจะเน้นบริเวณที่มีการเปลี่ยนแปลงความเข้มอย่างรวดเร็ว ดังนั้นจึงใช้ตรวจจับขอบ
Laplacian() วิธีการของคลาส Imgproc ใช้ Laplacian Transform กับรูปภาพที่กำหนด วิธีนี้ยอมรับ -
-
วัตถุ Mat สองรายการที่แสดงภาพต้นทางและปลายทาง
-
ตัวแปรจำนวนเต็มสี่ตัวที่แทนค่าความลึก ขนาด มาตราส่วน และเดลต้าของการแปลงค่า
-
ค่าจำนวนเต็มแสดงถึงเส้นขอบ
ตัวอย่าง
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class LaplacianTransform extends Application {
public void start(Stage stage) throws IOException {
//Loading OpenCV library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//Creating Mat objects to store source and destination images
Mat src = new Mat();
Mat dst = new Mat();
//Reading Image
src = Imgcodecs.imread("D:\\Images\\road3.jpg");
//Applying Laplacian transform
Imgproc.Laplacian( src, dst, CvType.CV_16S, 3, 1, 0, Core.BORDER_DEFAULT );
//Imgproc.Laplacian(src, dst, ddepth, ksize, scale, delta, borderType);
// converting back to CV_8U
Core.convertScaleAbs( dst, dst );
//Converting matrix to JavaFX writable image
Image img = HighGui.toBufferedImage(dst);
WritableImage writableImage= SwingFXUtils.toFXImage((BufferedImage) img, null);
//Setting the image view
ImageView imageView = new ImageView(writableImage);
imageView.setX(10);
imageView.setY(10);
imageView.setFitWidth(575);
imageView.setPreserveRatio(true);
//Setting the Scene object
Group root = new Group(imageView);
Scene scene = new Scene(root, 595, 400);
stage.setTitle("Laplacian Transform");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
launch(args);
}
} ใส่รูปภาพ

ผลลัพธ์
ในการดำเนินการ โปรแกรมดังกล่าวจะสร้างหน้าต่างต่อไปนี้ -
