AI13 Opencv
AI13 Opencv
OpenCV
▪Learning contents
13.1 Image data
13.2 Image visualization using Matplotlib
13.3 OpenCV module
13.4 Filters for image processing
13.5 Manipulating image data
13.6 Question
13.1 Image data
Two-dimen- 0 to black , If 1 is
sional arrays 0 displayed in
and 1 white, it becomes
this image.
Red
If one pixel is expressed
Green using the Red + Green +
Blue channels, a color
Blue pixel can be expressed.
Image data
• The mandrill monkey has various colors on its face, so it is often used
as an example image.
waitkey() function allows
users to display a window for
given milliseconds or until
any key is pressed. It takes
time in milliseconds as a pa-
rameter and waits for the
given time to destroy the win-
dow, if 0 is passed in the argu-
ment it waits till any key is
pressed.
OpenCV module
You can
draw straight
lines or
squares on
In OpenCV,
the picture.
colors repre-
sent their com-
ponent values
in the order of
Blue, Green,
and Red.
OpenCV module
OpenCV module
addWeighted Function:
img = cv2.addWeighted(source1, alpha, source2, beta, gamma[, dst[, dtype]])
This function
allows you to
adjust the
transparency
using the track
bar.
OpenCV module
Combine the
two images us-
ing the top
trackbar bar.
OpenCV module
• Using a mask, only a specific part of an image can be left or disappeared.
Mask image
• The inside of the image to be used as a mask is expressed in black and the background
is white. Therefore, it can be understood that all internal color components are set to 0
and the background is set to 1.
OpenCV module
• The black part is zeroing out whatever the background image is. And the 1 of
the mask, that is, the white part, is the background image value and deter-
mines the color of the corresponding pixel.
• In other words, the bitwise AND operation covers the background image with
the black part of the mask.
color of the
se
two images
bitwi
background image
Bitwise XOR
bitw
ise O
R
Ddepth: means desired depth of the destination image. It has information about
what kinds of data stored in an image, and that can be unsigned char ( CV_8U),
signed char (CV_8S), unsigned short (CV_16U), and so on...
Filters for image processing
Filter2D
Image my_mask
• See the black and white image on the right in the picture above. The white
part is where the original image was blue. By using the extracted image as
a mask, only blue pixels can be picked out from the original image.
• Since the two images have different shapes, bitwise_and()cannot be ap-
plied.
Filters for image processing
Filter2D
kernel 1
kernel 2
Filters for image processing
Blur filter
Filters for image processing
GaussianBlur
• cv2.THRESH_BINARY - sets the pixel value that satisfies the condition to the
maximum value and the pixel value that does not satisfy the condition to be 0
• cv2. THRESH_BINARY_INV - sets pixel values that satisfy the condition to 0,
and sets the pixel value that does not satisfy the condition to the maximum value
• cv2. THRESH_TRUNC- Sets the pixel value that satisfies the condition as the
maximum value, otherwise sets it to the original value.
• cv2. THRESH_TOZERO - Set pixel values that satisfy the condition as original
values, and pixel values that do not satisfy the condition as 0
• cv2. THRESH_TOZERO_INV - Set pixel values that satisfy the condition to 0,
and set the pixel values that do not satisfy the condition to the original value
Manipulating image data
Reference
https://docs.opencv.org/3.4.3/d7/d4d/tutorial_py_thresholding.html
Manipulating image data
13.6 Question