• Home
  • Breaking
  • Politics
  • Tech
    • Trick And Tips
    • smartphone
  • Economy
  • Business
    • Entrepreneur
    • Markets
    • Investment
    • Money
  • Travel
    • Travel Tips
  • Health
  • Sports
    • Cricket
    • Tennis
    • Women’s Cricket
    • Football
    • rugby
Monday, April 19, 2021
  • Login
No Result
View All Result
PostInTrend
  • Home
  • Breaking
  • Politics
  • Tech
    • Trick And Tips
    • smartphone
  • Economy
  • Business
    • Entrepreneur
    • Markets
    • Investment
    • Money
  • Travel
    • Travel Tips
  • Health
  • Sports
    • Cricket
    • Tennis
    • Women’s Cricket
    • Football
    • rugby
  • Insurance
  • Jobs
  • Home
  • Breaking
  • Politics
  • Tech
    • Trick And Tips
    • smartphone
  • Economy
  • Business
    • Entrepreneur
    • Markets
    • Investment
    • Money
  • Travel
    • Travel Tips
  • Health
  • Sports
    • Cricket
    • Tennis
    • Women’s Cricket
    • Football
    • rugby
  • Insurance
  • Jobs
No Result
View All Result
PostInTrend
No Result
View All Result
Home Breaking

OpenCV bitwise_and | Working of bitwise_and() Operator in OpenCV

08/04/2021
in Breaking, Education
OpenCV bitwise_and | Working of bitwise_and() Operator in OpenCV
Share on FacebookShare on Twitter

OpenCV bitwise_and | Working of bitwise_and() Operator in OpenCV

Introduction to OpenCV bitwise_and

Whenever we are dealing with images while solving computer vision problems, there arises a necessity to wither manipulate the given image or extract parts of the given image based on the requirement, in such cases we make use of bitwise operators in OpenCV and when the elements of the arrays corresponding to the given two images must be combined bit wise, then we make use of an operator in OpenCV called but wise and operator using which the arrays corresponding to the two images can be combined resulting in merging of the two images and bit wise operation on the two images returns an image with the merging done as per the specification.

The syntax to define bitwise_and() operator in OpenCV is as follows:

bitwise_and(source1_array, source2_array, destination_array, mask)

  • where source1_array is the array corresponding to the first input image on which bitwise and operation is to be performed,
  • source2_array is the array corresponding to the second input image on which bitwise and operation is to be performed,
  • destination_array is the resulting array by performing bitwise operation on the array corresponding to the first input image and the array corresponding to the second input image and
  • mask is the mask operation to be performed on the resulting image and it is optional.

Working of bitwise_and() Operator in OpenCV

Working of bitwise_and() operator in OpenCV is as follows:

  • In order to be able to perform bit wise conjunction of the two arrays corresponding to the two images in OpenCV, we make use of bitwise_and operator.
  • To be able to make use of bitwise_and operator in our program, we must import the module cv2.
  • The images whose arrays are to be combined using bitwise_and operator are read using imread() function.
  • Then the corresponding arrays of those images are passed to the bitwise_and operator.
  • The bitwise_and operator returns an array that corresponds to the resulting image from the merger of the given two images.
  • The operation of bitwise_and can be done on images having same dimensions only.

Examples of OpenCV bitwise_and

Following are the examples are given below:

Example #1

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

Code:

#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the two images that are to be merged using imread() function
imageread1 = cv2.imread('C:/Users/admin/Desktop/plane.jpg')
imageread2 = cv2.imread('C:/Users/admin/Desktop/car.jpg')
#using bitwise_and operation on the given two images
resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None)
#displaying the merged image as the output on the screen
cv2.imshow('Merged_image', resultimage)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

OpenCV bitwise_and-1.1

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Example #2

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

 Code:

#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the two images that are to be merged using imread() function
imageread1 = cv2.imread('C:/Users/admin/Desktop/logo.png')
imageread2 = cv2.imread('C:/Users/admin/Desktop/educbalogo.jpg')
#using bitwise_and operation on the given two images
resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None)
#displaying the merged image as the output on the screen
cv2.imshow('Merged_image', resultimage)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

OpenCV bitwise_and-1.2

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Example #3

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

 Code:

#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the two images that are to be merged using imread() function
imageread1 = cv2.imread('C:/Users/admin/Desktop/tree.jpg')
imageread2 = cv2.imread('C:/Users/admin/Desktop/educbatree.jpg')
#using bitwise_and operation on the given two images
resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None)
#displaying the merged image as the output on the screen
cv2.imshow('Merged_image', resultimage)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

OpenCV bitwise_and-1.3

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Example #4

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

 Code:

#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the two images that are to be merged using imread() function
imageread1 = cv2.imread('C:/Users/admin/Desktop/plane1.jpg')
imageread2 = cv2.imread('C:/Users/admin/Desktop/educbatree.jpg')
#using bitwise_and operation on the given two images
resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None)
#displaying the merged image as the output on the screen
cv2.imshow('Merged_image', resultimage)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

OpenCV bitwise_and-1.4

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of the bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Recommended Articles

This is a guide to OpenCV bitwise_and. Here we also discuss the introduction and syntax of opencv bitwise_and along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Bitwise Operators in PHP
  2. Bitwise Operators in C++
  3. Bitwise Operators in C#
  4. Bitwise Operators in JavaScript

The post OpenCV bitwise_and appeared first on EDUCBA.

Source link

RelatedPosts

Durant hurts thigh, exits in 1st quarter vs. Heat

Durant hurts thigh, exits in 1st quarter vs. Heat

19/04/2021
More than half of all Americans now partially vaccinated, one third fully jabbed up, CDC data shows

More than half of all Americans now partially vaccinated, one third fully jabbed up, CDC data shows

19/04/2021

Leicester’s Iheanacho shows he’s ready to lead after sending Foxes to FA Cup final

Ted Williams memorabilia enters the NFT market

Damian Lewis Honors Late Wife Helen McCrory in Heartbreaking Tribute

Train Crash in Egypt Kills at Least 11

Load More
Next Post
SQLite COUNT | How count function works in SQLite?

SQLite COUNT | How count function works in SQLite?

Menlo Park: Ann’s Coffee Shop diner closing after 75 years

Menlo Park: Ann’s Coffee Shop diner closing after 75 years

Connect with us

Recommended

Thousands Protest In London To Support Indian Farmers, Several Arrested

Thousands Protest In London To Support Indian Farmers, Several Arrested

4 months ago

NIA Gives Nod to Make Accused Sandip Nair Approver in Kerala Gold Smuggling Case

7 months ago

Popular News

Plugin Install : Popular Post Widget need JNews - View Counter to be installed
PostInTrend

© 2021 Postintrend

Get In Touch

  • Advertise
  • Contact
  • Disclaimer
  • Write For Us

Follow Us

No Result
View All Result
  • Home
  • Breaking
  • Politics
  • Tech
    • Trick And Tips
    • smartphone
  • Economy
  • Business
    • Entrepreneur
    • Markets
    • Investment
    • Money
  • Travel
    • Travel Tips
  • Health
  • Sports
    • Cricket
    • Tennis
    • Women’s Cricket
    • Football
    • rugby

© 2021 Postintrend

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Go to mobile version