0% found this document useful (0 votes)
32 views26 pages

4 - Computer Vision 24-10-2023.pdf - 083200

Uploaded by

loosolooso2000
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)
32 views26 pages

4 - Computer Vision 24-10-2023.pdf - 083200

Uploaded by

loosolooso2000
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

Introduction to Robots and

computer vision
Presented by:
Dr . Mona Hussein Alnaggar
2023-2024
1st term
Lecture 4
Objectives:

• Image Dimensions.

• Geometric Transformations of Images


• Scaling.
• Rotation.
• Perspective Transformation.
• Morphological Transformations
Image Dimensions cont.:
Image Dimensions:
• [Link] returns (Height, Width, Number of Channels)

• where
➢Height represents the number of pixel rows in the image or the number of pixels in
each column of the image array.
➢Width represents the number of pixel columns in the image or the number of pixels
in each row of the image array.
➢Number of Channels represents the number of components used to represent each
pixel.
Image Dimensions cont.:
Scaling
• Scaling is just resizing of the image.
• use [Link]() for Scaling.

• use cv2.INTER_AREA for shrinking.

• use cv2.INTER_CUBIC (slow) & cv2.INTER_LINEAR for zooming.

• By default, interpolation method used is cv2.INTER_LINEAR for all resizing


purposes.
Scaling example
Translation

• Translation is the shifting of object’s location. If you know the


shift in (x,y) direction, let it be , you can create the
transformation matrix as follows:
Transformation Code:

Third argument of the [Link]() function is the size of


the output image, which should be in the form of (width,
height). Remember width = number of columns, and height =
number of rows.
Rotation

• Rotation of an image for an angle is achieved by the


transformation matrix of the form:
Rotation using OpenCV
• OpenCV provides scaled rotation with adjustable center of rotation so
that you can rotate at any location you prefer. Modified transformation
matrix is given by:

• Where:
Rotation in OpenCV:

• To find this transformation matrix, OpenCV provides a function,


cv2.getRotationMatrix2D. Check coming example which rotates the
image by 90 degree with respect to center without any scaling.
Rotation code:
Perspective Transformation:
• To find this transformation matrix, you need 4 points on the input
image and corresponding points on the output image.

• Among these 4 points, 3 of them should not be collinear.

• Then transformation matrix can be found by the function:


[Link].

• Then apply [Link] with this 3x3 transformation matrix.


Perspective Transformation Code:
Morphological Transformations
-It deals with tools for extracting image components that are useful in the
representation & description of shape.
Morphological Transformations
• Morphological transformations are some simple operations based on the image shape.

• It is normally performed on binary images. It needs two inputs, one is our original image, second one is
called structuring element or kernel which decides the nature of operation. Two basic morphological
operators are Erosion and Dilation.

• Then its variant forms like Opening, Closing, Gradient etc also comes into play.

• morphological operations like:


• Erosion,

• Dilation,

• Opening,

• Closing
1. Erosion

• The basic idea of erosion is just like soil erosion only, it erodes away the boundaries of foreground
object (Always try to keep foreground in white).

• The kernel slides through the image (as in 2D convolution).

• A pixel in the original image (either 1 or 0) will be considered 1 only if all the pixels under the
kernel is 1, otherwise it is eroded (made to zero).

• all the pixels near boundary will be discarded depending upon the size of kernel. So the thickness
or size of the foreground object decreases or simply white region decreases in the image.

• It is useful for removing small white noises, detach two connected objects etc.
Erosion Result:

Original Erosion
2. Dilation
• It is just opposite of erosion.

• Here, a pixel element is ‘1’ if at least one pixel under the kernel is ‘1’.

• So it increases the white region in the image or size of foreground object increases.

• Normally, in cases like noise removal, erosion is followed by dilation. Because, erosion
removes white noises, but it also shrinks the object.

• So we dilate it. Since noise is gone, they won’t come back, but the object area increases.

• It is also useful in joining broken parts of an object.


Applying Dilation
dilation = [Link](img,kernel,iterations = 1)

Original Dilation
3. Opening
• Opening is just another name of erosion followed by dilation. It is
useful in removing noise, Here we use the function,
[Link]()
• opening = [Link](img, cv2.MORPH_OPEN,
kernel)
4. Closing
• Closing is reverse of Opening, Dilation followed by Erosion. It is
useful in closing small holes inside the foreground objects, or small
black points on the object.
• opening = [Link](img, cv2.MORPH_OPEN,
kernel)
5. Morphological Gradient
• It is the difference between dilation and erosion of an image.
• The result will look like the outline of the object.
• gradient = [Link](img, cv2.MORPH_GRADIENT,
kernel)

You might also like