0% found this document useful (0 votes)
6 views15 pages

Lecture3-2 in Computer Vision

From Noura al hakeem

Uploaded by

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

Lecture3-2 in Computer Vision

From Noura al hakeem

Uploaded by

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

FACE IDENTIFIED

Computer Vision
MATCH
Lecture-Three
Morphological
Operations

PRODUCTS IDENTIFIED EMOTION IDENTIFIED

Eng: Noor Alhakim


Filtering in Spatial Domain
• Sobel Filter
• Canny Filter

Thresholding
• Thresholding basic functions

Lecture Plan Morphological Operations


• Erosion
• Dilation
• Opening
• Closing
• Morphological Gradient
Filtering in Spatial Domain

• Sobel Filter

image = cv.imread("sudoko.jpg",0)
cv.imshow("Image",image)

cv.waitKey(0)
sobel_x_filtered_image = cv.Sobel(image,cv.CV_64F, 1, 0, ksize=3)
sobel_y_filtered_image = cv.Sobel(image,cv.CV_64F, 0, 1, ksize=3) Vertical Edges
sobel_x_filtered_image =cv.convertScaleAbs(sobel_x_filtered_image)
sobel_y_filtered_image =cv.convertScaleAbs(sobel_y_filtered_image)
cv.imshow("sobel_x_filtered_image",sobel_x_filtered_image);
cv.imshow("sobel_y_filtered_image",sobel_y_filtered_image);

cv.waitKey(0)
Horizontal Edges
Filtering in Spatial Domain

• The Results

Original Horizontal Edges Vertical Edges


Filtering in Spatial Domain

• Canny Filter

img= cv.imread('home.jpg')

image_gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
filtered_image =
cv.Canny(image_gray,threshold1=100, threshold2=200)

cv.imshow('image_original',img);
cv.imshow('filtered_image',filtered_image);
cv.waitKey(0)
Image thresholding is a simple, yet effective, way of
partitioning an image into a foreground and
background

Thresholding
Thresholding

img = cv.imread('numbers.jpg', 0)
ret, thresh1 = cv.threshold(img, 127,255,
cv.THRESH_BINARY)
ret, thresh2 = cv.threshold(img, 127,255,
cv.THRESH_BINARY_INV)
ret, thresh3 = cv.threshold(img, 127,255,
cv.THRESH_TRUNC)
ret, thresh4 = cv.threshold(img, 127,255,
cv.THRESH_TOZERO)
ret, thresh5 = cv.threshold(img, 127,255,
cv.THRESH_TOZERO_INV)
Morphological transformations are some simple
operations based on the image shape.
It is normally performed on binary images.

Morphological
Operations
Erosion
Original

img = cv.imread('circles.png', 0)
kernel = np.ones((5,5),np.uint8)
#Erosion
erosion = cv.erode(img,kernel,iterations= 1)
cv.imshow("erosion",erosion)
cv.waitKey(0)
Iteration = 1

Try Iteration = 2 and


see the result
Dilation
Original

img = cv.imread('circles.png', 0)
kernel = np.ones((5,5),np.uint8)

#Dilation
dilation = cv.dilate(img,kernel,iterations= 1)
cv.imshow(“dilation", dilation)
cv.waitKey(0)
Iteration = 1

Try Iteration = 2 and


see the result
Opening
Original
Opening = Erosion + Dilation
It is useful in removing noise.

img = cv.imread('circles.png', 0)
kernel = np.ones((5,5),np.uint8)

#Opening
Opening=cv.morphologyEx(img,cv.MORPH_OPEN,kernel) Opening
cv.imshow("opening",opening)
cv.waitKey(0)
Closing
Original
Closing = Dilation + Erosion
It is useful in closing small holes inside the
foreground objects, or small black points on the
object.

img = cv.imread(j.png', 0)
kernel = np.ones((5,5),np.uint8)

#Closing Closing
Closing=cv.morphologyEx(img,cv.MORPH_CLOSE,kernel)
cv.imshow(“closing",Closing)
cv.waitKey(0)
Morphological Gradient
Original
It is the difference between dilation and erosion
of an image.
Gradient = Dilation - Erosion
The result will look like the outline of the object.

img = cv.imread('j.png', 0)
kernel = np.ones((5,5),np.uint8)

#Gradient Gradient
Gradient=cv.morphologyEx(img,cv.MORPH_GRADIENT,kernel)
cv.imshow(“Gradient ", Gradient)
cv.waitKey(0)
Homework

Take an image with “High Details” :


1. Apply more than one blur filter on that image.
2. Apply Canny filter after blurring.
3. Apply a Morphological operations.
4. Can you extract more edge details from that image after applying
morphological operations? why?
5. Do a simple python script.
6. Do a report using Arabic language.
7. Number of participants: Two.
8. Deadline: 4/11/22.
That’s All

You might also like