- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain OpenCV Laplacian Transformation using java Example
The Laplacian transform on an image highlights the regions where there is a rapid intensity change. Therefore, it is used to detect edges.
The Laplacian() method of the Imgproc class applies Laplacian Transform on the given image, this method accepts −
Two Mat objects representing the source and destination images.
Four integer variables representing the depth, size, scale and, delta values of the transform.
An integer value representing the border.
Example
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); } }
Input Image
Output
On executing, the above program generates the following windows −
Advertisements