0% found this document useful (0 votes)
22 views

Programming Assignment 1

More about CAP 5416 UF

Uploaded by

aryan.atre
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Programming Assignment 1

More about CAP 5416 UF

Uploaded by

aryan.atre
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Programming Assignment 1 – Aryan Atre

Q1]

Firstly, matrix A and translation vector b in the given affine map:

A = [1 1; 1 3] and b = [4; 0]

Now, let's decomposing A into shear, rotation, and scaling matrices:

Shear matrix (S): Let's assume a horizontal shear [1 k; 0 1]

Rotation matrix (R): [cos(θ) -sin(θ); sin(θ) cos(θ)]

Scaling matrix (M): [sx 0; 0 sy]

Shear factor k = 1

Rotation angle θ = π/4 (45 degrees)

Scaling factors sx = 2, sy = 2
The code applies a series of affine transformations (shear, rotation,
scaling, and translation) to an image step by step. The key steps are:

1. Shear Transformation: Skews the image horizontally.

2. Rotation Transformation: Rotates the image by 45 degrees.

3. Scaling Transformation: Doubles the image size.

4. Translation: Shifts the image 4 units to the right.

The transformations are applied one after the other or merged into a
single matrix. The algorithm does these transformations using matrix
multiplication and warps the image using cv2.warpAffine(). Pixel values in
the altered image are smoothed using bilinear interpolation. Each
modification is applied, and the final image is trimmed to get rid of extra
white space. The resultant output for both a genuine image and a simple
square shows the combined effect of these modifications.

The visual effects produced by applying the same modifications to an


actual image are comparable. Shearing, rotation, scaling, and translation
are applied to the original image, causing noticeable movement and
distortion.
Q3]

Procedure/Algorithm

1. Gaussian Pyramid: Constructing a Gaussian pyramid for each


image by repeatedly by applying Gaussian filtering and
downsampling.

2. Laplacian Pyramid: Generating a Laplacian pyramid by


subtracting the upsampled Gaussian image of the next level from
the current level. This captures the high-frequency details.

3. Mask Creation: Create two masks:

o Half Mask: Value of 1 for the left half and 0 for the right.

o Circular Mask: Value of 1 inside a circle and 0 outside.

4. Blending: For each level of the Laplacian pyramid, blend the


images using the masks:

5. Reconstruction: Reconstruct the final blended image from the


blended Laplacian pyramid by upsampling and adding the layers.

6.
Observations and Results

 Half Mask Blending: Produces a sharp transition between images,


creating a clear boundary.

 Circular Mask Blending: Results in a smooth, radial transition,


minimizing visible edges and achieving a seamless blend.

Reasoning

 Multi-Resolution Blending: Separating low and high frequencies


allows for better detail preservation and a more natural blend than
simple alpha blending.

 Masking: Using masks allows for flexible control over which image
dominates at each part of the final blend, resulting in aesthetically
pleasing transitions.
Q2] This algorithm projects an image through a camera model defined by
the given projection matrix P using a series of rotations to extract intrinsic
(K) and extrinsic (R) parameters. The camera centre in world coordinates
is also computed. The final step involves using the camera's intrinsic
matrix (K) and projective transformations to map an old image onto a new
image plane.

Step-by-Step Explanation:

1. Projection Matrix Construction (P): The projection matrix P is


given by:

The submatrix M is the 3x3 part of P, which contains the camera's rotation
and intrinsic parameters.

2. Determinant Calculation: The determinant of the 3x3 submatrix


M is calculated to ensure that the matrix is invertible. If the
determinant is non-zero, the matrix can be decomposed into
rotation and intrinsic matrices.

3. Rotation Matrix Extraction: Using M, we decompose it into the


product of the intrinsic matrix K and rotation matrix R using three
successive rotations:

o X-axis rotation (R1): The angle x1 is computed using the


arctangent of the elements of M. This step rotates the matrix
to align it with the X-axis.

o Y-axis rotation (R2): Another rotation aligns the camera with


the Y-axis, calculated using MR1.

o Z-axis rotation (R3): The final rotation aligns the matrix with
the Z-axis.
After applying all three rotations, the final rotation matrix R is derived by
multiplying R1, R2, and R3.

4. Camera Canter Calculation: The camera canter C in world


coordinates is computed as:

C=−(QR)−1p4C = - (QR)^{-1} p_4C=−(QR)−1p4

Here, Q is the product of M and the extracted rotations, and p4 is the last
column of the projection matrix P. This gives the location of the camera in
world space.

5. Intrinsic Matrix (K) Calculation: The intrinsic matrix K is derived


from the matrix Q. Some modifications are made to ensure that the
matrix components are correctly scaled and normalized.

Image Projection:

o We take an image and project each pixel from the image onto
the new image plane using the intrinsic matrix K.

o The projected coordinates are computed for each pixel by


multiplying the camera coordinates with the intrinsic matrix.

o The pixel values are mapped to the new image plane based on
the calculated projection coordinates.

You might also like