Comput
er
Vision
by
Arefin Labib (1904111)
Concept of Image
21 45 12 56 77 122
.. .. .. .. .. .. ..
.. .. .. .. .. .. ..
.. .. .. .. .. .. ..
.. .. .. .. .. .. ..
.. .. .. .. .. .. ..
.. .. .. .. .. .. ..
visual representation of an object, scene, or information.
Reading Image
PIL OpenCV
Python Imaging Library.
Deprecated, PILLOW is
the improved version.
Types of Image
● Binary Image
Pixels are either black or white
Types of Image
● Binary Image
Pixels are either black or white
● Grayscale Image
Pixels range from 0 to 255
Grayscale vs BW image
255 0 255
0 255 0
0 0 255
255 18 220
25 201 33
7 45 255
Types of Image
● Binary Image
Pixels are either black or white
● Grayscale Image
Pixels range from 0 to 255
● RGB Image
Each pixel has 3 color channel
Pixel Value
● For BW Image
img_array[120, 344] = 0 or 255 and img_array is 2D array
● For Grayscale Image
img_array[120, 344] = ranged from 0 to 255 and img_array is 2D array
● For RGB Image
img_array[120, 344] = [x, y, z] ; x, y and z ranged from 0 to 255 and
img_array is 3D array
RED GREEN BLUE
PIL vs OpenCV
PIL: for basic image processing and manipulation
OpenCV: Designed for advanced computer vision and real-time image
processing
Video Processing is done with OpenCV
PIL vs OpenCV
PIL: Slower for large-scale processing
OpenCV: Optimized and faster, Can be used in C++ too
PIL: Uses RGB format
OpenCV: Uses BGR format by default
PIL vs OpenCV
PIL: Uses PIL Image objects
OpenCV: Uses NumPy arrays (numpy.ndarray)
Converting RGB to Grayscale
Simple Approach
Gray = (R+G+B)/3
Converting RGB to Grayscale
Maximum Method
Gray = max(R, G, B)
Converting RGB to Grayscale
Weighted Sum Method (Luminance Method)
Gray=0.2989×R + 0.5870×G + 0.1140×B
Brainstorm
Individual channels (R-channel, G-channel, B-channel) of
the images are -
A) Black and White
B) Grayscale
C) Will show specific color (Red only, Green only, Blue
only)
Brainstorm
Individual channels (R-channel, G-channel, B-channel) of
the images are -
A) Black and White
B) Grayscale
C) Will show specific color (Red only, Green only, Blue
only)
Basic Image Operations
● Resizing
resized_image = cv2.resize(img_array, (200, 100))
● Flipping
flip_vertical = cv2.flip(image, 0)
flip_horizontal = cv2.flip(image, 1)
flip_both = cv2.flip(image, -1)
● Cropping
cropped_image = image[50:200, 100:300]
Drawing Shapes in Image
● Circle
● Rectangle
● Line
Rectangle Drawing
cv2.rectangle(image, (50, 50), (250, 200), (0, 255, 0), 3)
cv2.rectangle(
image, # numpy.ndarray
(50, 50), # upper left pixel
(250, 200), # lower right pixel
(0, 255, 0), # color
3 thickness
)
Circle Drawing
cv2.circle(image, (350, 150), 50, (255, 0, 0), -1)
cv2.circle(
image,
(350, 150), # Center
50, # Radius
(255, 0, 0),
-1
)
Line Drawing
cv2.line(image, (100, 300), (400, 400), (0, 0, 255), 5)
cv2.line(
image,
(100, 300), # Starting point
(400, 400), # Ending point
(0, 0, 255),
5
)
Video Processing
import cv2
cap = cv2.VideoCapture("input_video.mp4")
while True:
ret, frame = cap.read()
cv2.imshow("Video", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Video Processing
FPS: File/Frame per second
fps = cap.get(cv2.CAP_PROP_FPS)

introtoComputerVisionbyarefinlabibbhai.pptx

  • 1.
  • 2.
    Concept of Image 2145 12 56 77 122 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. visual representation of an object, scene, or information.
  • 3.
    Reading Image PIL OpenCV PythonImaging Library. Deprecated, PILLOW is the improved version.
  • 4.
    Types of Image ●Binary Image Pixels are either black or white
  • 5.
    Types of Image ●Binary Image Pixels are either black or white ● Grayscale Image Pixels range from 0 to 255
  • 6.
    Grayscale vs BWimage 255 0 255 0 255 0 0 0 255 255 18 220 25 201 33 7 45 255
  • 7.
    Types of Image ●Binary Image Pixels are either black or white ● Grayscale Image Pixels range from 0 to 255 ● RGB Image Each pixel has 3 color channel
  • 8.
    Pixel Value ● ForBW Image img_array[120, 344] = 0 or 255 and img_array is 2D array ● For Grayscale Image img_array[120, 344] = ranged from 0 to 255 and img_array is 2D array ● For RGB Image img_array[120, 344] = [x, y, z] ; x, y and z ranged from 0 to 255 and img_array is 3D array
  • 9.
  • 10.
    PIL vs OpenCV PIL:for basic image processing and manipulation OpenCV: Designed for advanced computer vision and real-time image processing Video Processing is done with OpenCV
  • 11.
    PIL vs OpenCV PIL:Slower for large-scale processing OpenCV: Optimized and faster, Can be used in C++ too PIL: Uses RGB format OpenCV: Uses BGR format by default
  • 12.
    PIL vs OpenCV PIL:Uses PIL Image objects OpenCV: Uses NumPy arrays (numpy.ndarray)
  • 13.
    Converting RGB toGrayscale Simple Approach Gray = (R+G+B)/3
  • 14.
    Converting RGB toGrayscale Maximum Method Gray = max(R, G, B)
  • 15.
    Converting RGB toGrayscale Weighted Sum Method (Luminance Method) Gray=0.2989×R + 0.5870×G + 0.1140×B
  • 16.
    Brainstorm Individual channels (R-channel,G-channel, B-channel) of the images are - A) Black and White B) Grayscale C) Will show specific color (Red only, Green only, Blue only)
  • 17.
    Brainstorm Individual channels (R-channel,G-channel, B-channel) of the images are - A) Black and White B) Grayscale C) Will show specific color (Red only, Green only, Blue only)
  • 18.
    Basic Image Operations ●Resizing resized_image = cv2.resize(img_array, (200, 100)) ● Flipping flip_vertical = cv2.flip(image, 0) flip_horizontal = cv2.flip(image, 1) flip_both = cv2.flip(image, -1) ● Cropping cropped_image = image[50:200, 100:300]
  • 19.
    Drawing Shapes inImage ● Circle ● Rectangle ● Line
  • 20.
    Rectangle Drawing cv2.rectangle(image, (50,50), (250, 200), (0, 255, 0), 3) cv2.rectangle( image, # numpy.ndarray (50, 50), # upper left pixel (250, 200), # lower right pixel (0, 255, 0), # color 3 thickness )
  • 21.
    Circle Drawing cv2.circle(image, (350,150), 50, (255, 0, 0), -1) cv2.circle( image, (350, 150), # Center 50, # Radius (255, 0, 0), -1 )
  • 22.
    Line Drawing cv2.line(image, (100,300), (400, 400), (0, 0, 255), 5) cv2.line( image, (100, 300), # Starting point (400, 400), # Ending point (0, 0, 255), 5 )
  • 23.
    Video Processing import cv2 cap= cv2.VideoCapture("input_video.mp4") while True: ret, frame = cap.read() cv2.imshow("Video", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
  • 24.
    Video Processing FPS: File/Frameper second fps = cap.get(cv2.CAP_PROP_FPS)