
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to perform Bitwise And operation on two images using Java OpenCV?
You can compute bitwise conjunction between two images using the bitwise_and() method of the org.opencv.core.Core class.
This method accepts three Mat objects representing the source, destination and result matrices, calculates the bitwise conjunction of each every element in the source matrices and stores the result in the destination matrix.
Example
In the following Java example we are converting an image into binary and gray scale and calculating the bitwise conjunction of the results.
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 BitwiseAndExample { public static void main(String args[]) throws Exception { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the Image String file ="D://images//elephant.jpg"; Mat src = Imgcodecs.imread(file, Imgcodecs.IMREAD_GRAYSCALE ); HighGui.imshow("Grayscale Image", src); //Creating an empty matrix to store the results Mat dst = new Mat(src.rows(), src.cols(), src.type()); Mat threshold = new Mat(src.rows(), src.cols(), src.type()); Mat gray = new Mat(src.rows(), src.cols(), src.type()); //Converting the gray scale image to binary image Imgproc.threshold(src, threshold, 100, 255, Imgproc.THRESH_BINARY_INV); HighGui.imshow("Binary Image", threshold); //Applying bitwise and operation Core.bitwise_and(src, threshold, dst); HighGui.imshow("Bitwise And operation", dst); HighGui.waitKey(); } }
Input Image
Output
On executing, the above program generates the following windows −
Gray Scale Image −
Binary Image −
Bitwise And −
- Related Questions & Answers
- How to perform Bitwise XOR operation on two images using Java OpenCV?
- How to perform Bitwise OR operation on two images using Java OpenCV?
- How to perform Bitwise Not operation on images using Java OpenCV?
- Performing white TopHat operation on images using OpenCV
- Performing white BlackHat operation on images using OpenCV
- How to compare two images using Java OpenCV library?
- C++ Program to Perform Addition Operation Using Bitwise Operators
- Java Program to perform AND operation on BigInteger
- How to blend to images using OpenCV Java?
- How to match the key points of two images using OpenCV Java library?
- C program to perform intersection operation on two arrays
- C program to perform union operation on two arrays
- Reading and displaying images using OpenCV
- Arithmetic Operations on Images using OpenCV in Python
- Java Program to perform XOR operation on BigInteger
Advertisements