Phép biến đổi Laplacian trên ảnh làm nổi bật các vùng có cường độ thay đổi nhanh chóng. Do đó, nó được sử dụng để phát hiện các cạnh.
Laplacian () phương thức của lớp Imgproc áp dụng Biến đổi Laplacian trên hình ảnh đã cho, phương thức này chấp nhận -
-
Hai đối tượng Mat đại diện cho hình ảnh nguồn và hình ảnh đích.
-
Bốn biến số nguyên đại diện cho các giá trị độ sâu, kích thước, tỷ lệ và delta của biến đổi.
-
Một giá trị số nguyên đại diện cho đường viền.
Ví dụ
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);
}
} Hình ảnh đầu vào
Đầu ra
Khi thực thi, chương trình trên tạo các cửa sổ sau -