Day 18 : Image manipulation using OpenCV

Hello Guys
Previously we learn about data manipulation and web scraping.

Today we will learn about image manipulation. As we know everything in the computer is in bits(0s and 1s). And the image in the form of the pixel which in bits.


Computer Vision

Computer vision is a process by which we can understand the images and videos how they are stored and how we can manipulate and retrieve data from them. Computer Vision is the base or mostly used for Artificial Intelligence. Computer-Vision is playing a major role in self-driving cars, robotics as well as in photo correction apps.

How to manipulate Image?
OpenCV means open computer Vision. OpenCV is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage then Itseez. The library is cross-platform and free for use under the open-source BSD license.



How to install OpenCV?

pip install opencv-python



How to use OpenCV?
code:
import cv2
# Reading the image using imread() function
image = cv2.imread('1.jpg')

#display image
cv2.imshow("image",image)

# Extracting the height and width of an image
h, w = image.shape[:2]
# Displaying the height and width

print("Height = {},  Width = {}".format(h, w))


output:












Height = 340,  Width = 582

>>> 


#covert image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("gray",gray)

output:

















#Saving image
>>> cv2.imwrite("newimg.jpg",gray)

True


#Resizing image
image1=cv2.resize(image,(200,200))
 cv2.imshow("resize",image1)


output:














Rotating image
#Rotate image clockwise 90 degree
img_rotate_90_clockwise = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE)

cv2.imshow("rotate",img_rotate_90_clockwise)

output:




















Try Rotating:
cv2.ROTATE_90_COUNTERCLOCKWISE
cv2.ROTATE_180

Fliping Images
#0 represting flipcode (flip vertical)
flip=cv2.flip(image,0)
cv2.imshow("flip",flip)

#1 represting flipcode (flip horizontal)
flip1=cv2.flip(image,1)

cv2.imshow("flip1",flip1)


output:




























RGB image
code:
b = image.copy()
# set green and red channels to 0
b[:, :, 1] = 0
b[:, :, 2] = 0


g = image.copy()
# set blue and red channels to 0
g[:, :, 0] = 0
g[:, :, 2] = 0

r = image.copy()
# set blue and green channels to 0
r[:, :, 0] = 0
r[:, :, 1] = 0


# RGB - Blue
cv2.imshow('B-RGB', b)

# RGB - Green
cv2.imshow('G-RGB', g)

# RGB - Red

cv2.imshow('R-RGB', r)

output:



















❤❤Quarantine python group link ❤❤

8805271377 WhatsApp

Follow here ❤

@mr._mephisto_ Instagram 

There will be no restrictions just feel free to learn. 

Share and take one more step to share knowledge to others. 

Believe in yourself 🤟 you are awesome. 

Be safe, Be happy😁
Take care of yourself and your family 
Of course watch movies and series🤟😉 

And follow the guidelines of government

Comments

Popular posts from this blog

Day 16 : Pandas Basics

News website using Flask and news API - Working with templates : Part 5

Day 9 : Encapsulation and polymorphism