
- 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
Explain Top Hat and Black hat morphological operations in Java.
Morphological operations are the set of operations that process images according to the given shapes.
Erosion − Erosion is a morphological operation during which pixels are removed from the image boundaries.
Dilation − During is a morphological operation during which pixels are added to the image boundaries.
Where the total number of pixels added/removed depends on the dimensions of the structuring element used.
Morphological Opening − During this operation erosion is applied on the given input and on the result dilation is applied. This is used to remove small objects from the foreground of an image.
Morphological Closing − During this operation dilation is applied on the given input and on the result erosion is applied. This is used to remove small objects on an image.
A Morphological Top Hat is a difference between the given image and its opening.
Example
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 TopHatExample { public static void main(String args[]) { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading image data String file ="D:\Images\morph_input1.jpg"; Mat src = Imgcodecs.imread(file); //Creating destination matrix Mat dst = new Mat(src.rows(), src.cols(), src.type()); //Preparing the kernel matrix object Mat kernel = Mat.ones(5,5, CvType.CV_32F); //Applying dilate on the Image Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel); //Displaying the image HighGui.imshow("Blackhat Gradient", dst); HighGui.waitKey(); } }
Input Image
Output
A Morphological Black Hat is a difference between the closing and the given image.
Example
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 TopHatExample { public static void main(String args[]) { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading image data String file ="D:\Images\morph_input1.jpg"; Mat src = Imgcodecs.imread(file); //Creating destination matrix Mat dst = new Mat(src.rows(), src.cols(), src.type()); //Preparing the kernel matrix object Mat kernel = Mat.ones(5,5, CvType.CV_32F); //Applying dilate on the Image Imgproc.morphologyEx(src, dst, Imgproc.MORPH_BLACKHAT, kernel); //Displaying the image HighGui.imshow("Blackhat Gradient", dst); HighGui.waitKey(); } }
Input Image
Output
- Related Articles
- Difference between Fedora and Red Hat
- What is Gray Hat Hacking?
- What is Red Hat Cloud?
- White Hat Hacker: The What, Why, and How
- How to Make a Paper Hat?
- Who or what are white hat hackers?
- Explain Morphological Opening in OpenCV using Java.
- Explain morphological Closing in OpenCV using Java.
- Red Hat Updates OpenShift Container Platform with New Service Catalog
- Linux per-process resource limits - a deep Red Hat Mystery
- Explain Set relations and operations in TOC?
- Database operations in Java
- Explain the characteristics and operations of arrays in C language
- What are top 5 solutions to prevent black knees and elbow?
- Java 8 Streams and its operations
