0% found this document useful (0 votes)
23 views24 pages

Lec 3

Uploaded by

Raj Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views24 pages

Lec 3

Uploaded by

Raj Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Image Read, Write and Show

Lecture 3
OpencV Library Installation
• Pip install open-python
Topic Cover
• What is imread function in OpenCV?
• What is imshow function in OpenCV?
• What is Gray scale image and BGR image?
• Save image using imwrite fucntion
OVERVIEW
• OpenCV Python Tutorial For Beginners:
• To Read, Write, Show Images in OpenCV.
• we will se how to use cv2.imread('lena.jpg', -1) to read
and image,
• cv2.imshow('image', img) to show an image in a
window,
• cv2.waitKey(0) to wait for a key event,
• cv2.destroyAllWindows() to destroy all windows,
• cv2.imwrite('imagename.png', img) to write images to
file.
Read Image
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ")
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
Functions for Images
• IMAGE READ
• WRITE
&
• SHOW
Resize the Image
• import cv2 #openCV use as cv2 in python
• img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ")
• img1 = cv2 .resize(img1,(640,350))#width, height

• cv2.imshow("Original", img1)
• cv2.waitKey()
• cv2.destroyAllWindows()
Print(img1)
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ")
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
Imread(location, number)
• function accpets only two parameters
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",1)
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.waitKey()
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",1)
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)

cv2.destroyAllWindows()
#cv2.IMREAD_GRAYSCALE : Loads Image in
grayscale
img2 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",0)
img2 = cv2 .resize(img2,(1280,700))#width,
height
cv2.imshow("Image in gray scale ", img2)
print("Image in gray scale ==\n")

cv2.destroyAllWindows()
cv2.waitKey(3000)
Three Vs Single Channels
• runfile('C:/Users/S.TECH/untitled0.py', wdir='C:/Users/S.TECH')
• [[[243 245 239]
• [243 245 240]
• [243 244 239]
• ...
• [192 195 199]
• [192 195 199]
• [192 195 199]]

• [[246 247 243]


• [247 248 244]
• [248 249 244]
• ...
• [193 196 200]
• [193 196 200]
• [193 196 200]]

• [[241 242 240]


• [243 245 242]
• [247 247 245]
• ...
• [193 196 200]
• [193 196 200]
• [193 196 200]]

• ...

• [[198 217 250]


• [198 217 250]
• [198 217 250]
• ...
• [150 174 215]
• [130 155 199]
• [109 135 181]]

• [[196 217 249]


• [196 217 249]
• [196 217 249]
• ...
Gray Scale & Color Picture
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",1)
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
#cv2.IMREAD_GRAYSCALE : Loads Image in
grayscale
img2 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",0)
img2 = cv2 .resize(img2,(1280,700))#width,
height
cv2.imshow("Image in gray scale ", img2)
print("Image in gray scale ==\n")
cv2.waitKey()
cv2.destroyAllWindows()
Unchaned Code
• #CV2. IMREAD_UNCHANGED : Loads image as
such including alpha
• img3 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",-1)
• img3 = cv2 .resize(img3,(640,350))#width,
height
• cv2.imshow("Unchanged Image ", img3)
• print("Image In Original ==\n", img3)
• cv2.waitKey(0)
Code
Unchanged -1

You might also like