
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to implement Bilateral blur in OpenCV using Java?
You can blur an image by filtering it using a low-pass filter, this removes high frequency content (noise, edges) from an image. Bilateral Filtering is one of the blurring techniques provided by OpenCV, it −
removes noise efficiently
keeps the edges sharp
Comparatively slow
You can apply the bilateral filter on an image using the bilateralFilter() method, this method accepts
Two Mat objects representing the source and destination images.
An integer representing the diameter of the pixel neighborhood.
Two integer variables of the type integer representing the filter sigma in the color space and coordinate space.
An Integer object representing the type of the border used.
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.Mat; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class BilateralFilterExample extends Application { public void start(Stage stage) throws IOException { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading image data String file ="D:\Images\window.jpg"; Mat src = Imgcodecs.imread(file); //Creating destination matrix Mat dst = new Mat(src.rows(), src.cols(), src.type()); //Applying Bilateral filter Imgproc.bilateralFilter(src, dst, 25, 75, 75, Core.BORDER_DEFAULT); //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("Bilateral Filter Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]) { launch(args); } }
Input Image
Output
On executing, the above program generates the following output −
- Related Articles
- How to implement blur (averaging) in OpenCV using Java?
- How to implement Gaussian blur in OpenCV using Java?
- How to implement Median blur in OpenCV using Java?
- Bilateral filtering using OpenCV
- How to blur faces in an image using OpenCV Python?
- How to perform bilateral filter operation on an image in OpenCV using Python?
- Blurring an image using the OpenCV function blur()
- Blurring an image using the OpenCV function Gaussian Blur()
- OpenCV Python Program to blur an image?
- How to blur an image using Node Jimp blur() function?
- How to add blur-in and blur-out animation to a Polyline using FabricJS?
- How to draw polylines in OpenCV using Java?
- How to blend to images using OpenCV Java?
- How to draw a line in OpenCV using Java?
- How to draw an ellipse in OpenCV using Java?

Advertisements