0% found this document useful (0 votes)
8 views13 pages

02lab Image Operation

Uploaded by

Lloyd Vegafria
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)
8 views13 pages

02lab Image Operation

Uploaded by

Lloyd Vegafria
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/ 13

LABORATORY

ACTIVITY 2
(DIGITAL IMAGE
PROCESSING)
IMPORTING THE REQUIRED
LIBRARIES
 cv2 - Used for Image Processing
 Matplotlib - Used for Plotting and Visualization
 Numpy - Used for Scientific Computing
TO ANALYZE IMAGE
IMAGE DETAILS

Point your mouse anywhere on


the image to get the coordinates
and color.
IMAGE SCALING
Scaling is just resizing of the image. Whenever we resize an image, there are multiple ways
to fill in the pixel values. When we are enlarging an image, we need to fill up the pixel
values in between pixel locations. When we are shrinking an image, we need to take the
best representative value. When we are scaling by a non-integer value, we need to
interpolate values appropriately, so that the quality of the image is maintained.

There are multiple ways to do interpolation. If we are enlarging an image, it's preferable to
use linear or cubic interpolation. If we are shrinking an image, it's preferable to use the
area-based interpolation. Cubic interpolation is computationally more complex, and hence
slower than linear interpolation. But the quality of the resulting image will be higher.

OpenCV comes with a function resize() for this purpose. The size of the image can be
specified manually, or you can specify the scaling factor. Different interpolation methods
are used. Preferable interpolation methods are INTER_AREA for shrinking and INTER_CUBIC
(slow) & INTER_LINEAR for zooming. By default, the interpolation method INTER_LINEAR is
used for all resizing purposes.
AFFINE TRANSFORMATION
Affine transformation is a functional mapping
between two geometric (affine) spaces which
preserve points, straight and parallel lines as well
as ratios between points. Loosely speaking linear
transformation that results in, at least in the
context of image processing, one or more
manipulations like rotating, flipping, scaling or
shearing by applying a transformation matrix.
For the example we just need three points to get
the affine transformation matrix. We want the
three points in source points to be mapped to
the corresponding points in destination points.
To get the transformation matrix, we’ll use the OpenCV function getAffineTransform(). Once we
have the affine transformation matrix, we use the warpAffine() function to apply this matrix to
the original image.
AFFINE TRANSFORMATION
MIRROR IMAGE
IMAGE ROTATION
Rotation of an image for an angle theta is achieved by the transformation matrix
of the form:

OpenCV provides a function, getRotationMatrix2D().


PERSPECTIVE TRANSFORMATION
For perspective transformation, you need a 3x3
transformation matrix. Straight lines will remain straight
even after the transformation. To find this transformation
matrix, we 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
getPerspectiveTransform(). Then apply warpPerspective()
with this 3x3 transformation matrix.
Laboratory Activity 2
Create 4 python files based on the sample
codes.

Upload it in the LMS, including your


image.
- END -

You might also like