Top Banner
1

Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Aug 08, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Assignment-1Geometric Transformation and Interpolation

Page 2: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate Image and Perform Interpolation

1. Forward rotate image2. Inverse rotate image3. Rotation with interpolation

1. Nearest neighbour interpolation2. Bilinear interpolation

Page 3: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotation

• Initial location = (𝑥𝑥,𝑦𝑦)• After rotation

• 𝑥𝑥′,𝑦𝑦′ = ?

(x, y)𝜃𝜃

(x’, y’)

Page 4: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotation

• Initial location = (𝑥𝑥,𝑦𝑦)• After rotation

• 𝑥𝑥′,𝑦𝑦′ = ?𝑥𝑥′ = 𝑥𝑥 cos 𝜃𝜃 − 𝑦𝑦 sin(𝜃𝜃)𝑦𝑦′ = 𝑥𝑥 sin 𝜃𝜃 + 𝑦𝑦 cos 𝜃𝜃

(x, y)𝜃𝜃

(x’, y’)

Page 5: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotation

• Initial location = (𝑥𝑥,𝑦𝑦)• After rotation

• 𝑥𝑥′,𝑦𝑦′ = ?𝑥𝑥′ = 𝑥𝑥 cos 𝜃𝜃 − 𝑦𝑦 sin(𝜃𝜃)𝑦𝑦′ = 𝑥𝑥 sin 𝜃𝜃 + 𝑦𝑦 cos 𝜃𝜃Matrix Notation𝑥𝑥𝑥𝑦𝑦𝑥

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑥𝑥𝑦𝑦

(x, y)𝜃𝜃

(x’, y’)

Page 6: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotation

• Initial location = (𝑥𝑥,𝑦𝑦)• After rotation

• 𝑥𝑥′,𝑦𝑦′ = ?𝑥𝑥′ = 𝑥𝑥 cos 𝜃𝜃 − 𝑦𝑦 sin(𝜃𝜃)𝑦𝑦′ = 𝑥𝑥 sin 𝜃𝜃 + 𝑦𝑦 cos 𝜃𝜃Matrix Notation𝑥𝑥𝑥𝑦𝑦𝑥

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑥𝑥𝑦𝑦

(x, y)𝜃𝜃

(x’, y’)

Rotation Matrix

Page 7: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 8: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑥𝑥𝑥𝑦𝑦𝑥

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑥𝑥𝑦𝑦

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 9: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑥𝑥𝑥𝑦𝑦𝑥

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑥𝑥𝑦𝑦

𝑠𝑠𝑖𝑖 𝐴𝐴 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 10: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑠𝑠𝑖𝑖 𝐴𝐴 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃

𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃𝑥𝑥𝑥𝑦𝑦𝑥

= 𝐴𝐴𝑥𝑥𝑦𝑦

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 11: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑠𝑠𝑖𝑖 𝐴𝐴 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃

𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃𝑥𝑥𝑥𝑦𝑦𝑥

= 𝐴𝐴𝑥𝑥𝑦𝑦

𝐴𝐴𝑥𝑥𝑦𝑦

=𝑥𝑥𝑥𝑦𝑦𝑥

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 12: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑠𝑠𝑖𝑖 𝐴𝐴 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃

𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃𝑥𝑥𝑥𝑦𝑦𝑥

= 𝐴𝐴𝑥𝑥𝑦𝑦

𝐴𝐴𝑥𝑥𝑦𝑦

=𝑥𝑥𝑥𝑦𝑦𝑥

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 13: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑠𝑠𝑖𝑖 𝐴𝐴 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃

𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃𝑥𝑥𝑥𝑦𝑦𝑥

= 𝐴𝐴𝑥𝑥𝑦𝑦

𝑥𝑥𝑦𝑦

= 𝐴𝐴−1𝑥𝑥𝑥𝑦𝑦𝑥

(x, y)𝜃𝜃

(x’, y’) given

determine

Page 14: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse of (2X2) matrix

𝑠𝑠𝑖𝑖 𝐾𝐾 = 𝑎𝑎 𝑏𝑏𝑐𝑐 𝑑𝑑

Page 15: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse of (2X2) matrix

𝑠𝑠𝑖𝑖𝐾𝐾 = 𝑎𝑎 𝑏𝑏𝑐𝑐 𝑑𝑑

𝐾𝐾 𝑋𝑋 𝐾𝐾−1 = 𝐼𝐼 𝑠𝑠𝑑𝑑𝑖𝑖𝑠𝑠𝑖𝑖𝑠𝑠𝑖𝑖𝑦𝑦 𝑚𝑚𝑎𝑎𝑖𝑖𝑚𝑚𝑠𝑠𝑥𝑥𝐾𝐾−1 =

1𝑎𝑎𝑑𝑑 − 𝑏𝑏𝑐𝑐

𝑑𝑑 −𝑏𝑏−𝑐𝑐 𝑎𝑎

Page 16: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse of (2X2) matrix

𝑠𝑠𝑖𝑖 𝐾𝐾 = 𝑎𝑎 𝑏𝑏𝑐𝑐 𝑑𝑑

𝐾𝐾 𝑋𝑋 𝐾𝐾−1 = 𝐼𝐼 𝑠𝑠𝑑𝑑𝑖𝑖𝑠𝑠𝑖𝑖𝑠𝑠𝑖𝑖𝑦𝑦 𝑚𝑚𝑎𝑎𝑖𝑖𝑚𝑚𝑠𝑠𝑥𝑥𝐾𝐾−1 =

1𝑎𝑎𝑑𝑑 − 𝑏𝑏𝑐𝑐

𝑑𝑑 −𝑏𝑏−𝑐𝑐 𝑎𝑎

𝐴𝐴 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝐴𝐴−1 = 1𝑐𝑐𝑐𝑐𝑐𝑐2𝜃𝜃+𝑐𝑐𝑠𝑠𝑠𝑠2𝜃𝜃

𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃−𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 , 𝑐𝑐𝑜𝑜𝑜𝑜2𝜃𝜃 + 𝑜𝑜𝑠𝑠𝑠𝑠2𝜃𝜃=1

𝐴𝐴−1 = 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃−𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

Page 17: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑥𝑥𝑦𝑦

= 𝐴𝐴−1𝑥𝑥𝑥𝑦𝑦𝑥

𝑥𝑥𝑦𝑦

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃−𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑥𝑥𝑥𝑦𝑦𝑥 (x, y)

𝜃𝜃

(x’, y’) given

determine

Page 18: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Inverse Rotation

• Given 𝑥𝑥′,𝑦𝑦′ that has• Undergone rotation by 𝜃𝜃

• Find original location (𝑥𝑥,𝑦𝑦)Matrix Notation𝑥𝑥𝑦𝑦

= 𝐴𝐴−1𝑥𝑥𝑥𝑦𝑦𝑥

𝑥𝑥𝑦𝑦

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃−𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑥𝑥𝑥𝑦𝑦𝑥 (x, y)

𝜃𝜃

(x’, y’) given

determine

Inverse rotation matrix

Page 19: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Part 1: Forward Rotation

Forward rotate by𝜃𝜃 = 0.5 radians

(~28 deg)

Input

Output

Page 20: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Forward Rotation

Forward rotate by𝜃𝜃 = 0.5 radians

(~28 deg)

• Input:• Image• Theta (𝜃𝜃) - angle of rotation

Page 21: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Assumption

• To simplify,• We assume the following co-ordinate system

• O-Origin

x

yO

Page 22: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Assumption

• To simplify,• We assume the following co-ordinate

system• Theta denote rotation from x-axis,

towards y-axis

x

y

𝜽𝜽

O

Page 23: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate each pixel

• Let R be the rotated image and I the original image.

x

y

𝜽𝜽

O

(𝑠𝑠, 𝑗𝑗)

𝑠𝑠′ , 𝑗𝑗′

Page 24: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate each pixel

• Let R be the rotated image and I the original image.

• For every pixel 𝑠𝑠, 𝑗𝑗 in I • apply rotation by theta to get 𝑠𝑠′ , 𝑗𝑗′

in new image.

𝑠𝑠𝑥𝑗𝑗𝑥

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑠𝑠𝑗𝑗

x

y

𝜽𝜽

O

(𝑠𝑠, 𝑗𝑗)

𝑠𝑠′ , 𝑗𝑗′

Page 25: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate each pixel

• Let R be the rotated image and I the original image.

• For every pixel 𝑠𝑠, 𝑗𝑗 apply rotation by theta to get 𝑠𝑠′ , 𝑗𝑗′ in new image.

𝑠𝑠𝑥𝑗𝑗𝑥

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 −𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑠𝑠𝑗𝑗

• 𝑅𝑅 𝑠𝑠′, 𝑗𝑗′ = 𝐼𝐼(𝑠𝑠, 𝑗𝑗)

x

y

𝜽𝜽

O

(𝑠𝑠, 𝑗𝑗)

𝑠𝑠′ , 𝑗𝑗′

Page 26: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

Page 27: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

O

Page 28: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

O

Page 29: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y𝜽𝜽

O

Page 30: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

O

Page 31: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

O

Page 32: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

O

Page 33: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥 = minimum of x value amongst the rotated corners

𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦 ,𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 …1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)

1. Is also the new origin (N)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

O

N

Let I be the original image

Page 34: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Determine size of rotated image

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)

O

N

Let I be the original image

Page 35: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Create empty image

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)

O

N

Let I be the original image

Page 36: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate each pixel

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)4. For each (i, j) in original image:

1. Compute rotated location (I’, j’)

(i, j)

(i’, j’)

𝜽𝜽O

N

Let I be the original image

Page 37: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate each pixel

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)4. For each (i, j) in original image:

1. Compute rotated location (I’, j’)

(i, j)

(i’, j’)

𝜽𝜽O

N

This is with respect to the origin O

Let I be the original image

Page 38: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotate each pixel

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)4. For each (i, j) in original image:

1. Compute rotated location (I’, j’)

(i, j)

(i’, j’)

𝜽𝜽O

N

This is with respect to the origin O

Let I be the original image

Page 39: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Step 3: Compute new location with respect to N

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)4. For each (i, j) in original image:

1. Compute rotated location (i’, j’)2. 𝑠𝑠𝑁𝑁′ = 𝑠𝑠′ − 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑗𝑗𝑁𝑁′ = 𝑗𝑗′ − 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

(i, j)

(i’, j’)

𝜽𝜽O

N

This is with respect to the origin O

Let I be the original image (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ )

Page 40: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Step 3: Assign pixel value

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)4. For each (i, j) in original image:

1. Compute rotated location (i’, j’)2. 𝑠𝑠𝑁𝑁′ = 𝑠𝑠′ − 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑗𝑗𝑁𝑁′ = 𝑗𝑗′ − 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦3. R(𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) = I(i, j)

(i, j)

(i’, j’)

𝜽𝜽O

N

This is with respect to the origin O

Let I be the original image (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ )

Page 41: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Step 3: Assign pixel value

x

y

𝜽𝜽

1. Compute Rotation matrix2. Rotate corners

1. Get (𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦) (top left of the image)2. Get (𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥, 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦) (bottom right)

1. Rows = 𝑚𝑚𝑎𝑎𝑥𝑥𝑥𝑥 – 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥2. Cols = 𝑚𝑚𝑎𝑎𝑥𝑥𝑦𝑦 - 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦

3. Size of rotated image = (rows, cols)3. Create rotated image (R) of size (rows, cols)4. For each (i, j) in original image:

1. Compute rotated location (i’, j’)2. 𝑠𝑠𝑁𝑁′ = 𝑠𝑠′ − 𝑚𝑚𝑠𝑠𝑠𝑠𝑥𝑥, 𝑗𝑗𝑁𝑁′ = 𝑗𝑗′ − 𝑚𝑚𝑠𝑠𝑠𝑠𝑦𝑦3. R(𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) = I(i, j)

O

N

This is with respect to the origin O

Let I be the original image

Page 42: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Part 2: Reverse Rotation

Reverse rotate by𝜃𝜃 = 0.5 radians

(~28 deg)

Input

Output

Page 43: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Input:1. Rotated image2. Theta: the angle by which the

image was rotated 3. Origin (𝑂𝑂 = (𝑂𝑂𝑠𝑠 ,𝑂𝑂𝑗𝑗)): the origin

of the original image with respect to the origin of rotated image

4. Original shape: Shape of the original image before rotation

Page 44: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Input:1. Rotated image2. Theta: the angle by which the

image was rotated 3. Origin (𝑂𝑂 = (𝑂𝑂𝑠𝑠 ,𝑂𝑂𝑗𝑗)): the origin

of the original image with respect to the origin of rotated image

4. Original shape: Shape of the original image

Page 45: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

1. Compute inverse rotation matrix

O

Let R be rotated imageN

Page 46: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Create empty image with original shape

1. Compute inverse rotation matrix2. Create image (I) of shape (original

shape)O

Let R be rotated imageN

Page 47: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Iterate through each pixel and compute original location1. Compute inverse rotation matrix2. Create image (I) of shape (original

shape)3. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O

O

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

Let R be rotated image N

Page 48: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Iterate through each pixel and compute original location1. Compute inverse rotation matrix2. Create image (I) of shape (original

shape)3. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

O

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

Let R be rotated image N

Page 49: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Iterate through each pixel and compute original location1. Compute inverse rotation matrix2. Create image (I) of shape (original

shape)3. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)

O

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

(𝒊𝒊, 𝒋𝒋)

Let R be rotated image

𝜃𝜃

N

Page 50: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Iterate through each pixel and compute original location1. Compute inverse rotation matrix2. Create image (I) of shape (original

shape)3. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)

𝑠𝑠𝑗𝑗

= 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃 𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃−𝑜𝑜𝑠𝑠𝑠𝑠𝜃𝜃 𝑐𝑐𝑜𝑜𝑜𝑜𝜃𝜃

𝑠𝑠𝑥𝑗𝑗𝑥

O

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

(𝒊𝒊, 𝒋𝒋)

Let R be rotated image

𝜃𝜃

N

Page 51: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Assign values

1. Compute inverse rotation matrix2. Create image (I) of shape (original

shape)3. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)3. 𝐼𝐼 𝑠𝑠, 𝑗𝑗 = 𝑅𝑅(𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ )

O

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

(𝒊𝒊, 𝒋𝒋)

Let R be rotated image N

Page 52: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Output

Page 53: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Forward rotation

• Missing Pixel Values• Perform interpolation to fill in

missing values.

Page 54: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Part 3: Rotation with Interpolation

Page 55: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotation with interpolation𝜃𝜃 = 0.5 radians

(~28 deg)

Part 3: Rotation with interpolation

Input

Output

Page 56: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Rotation with interpolation𝜃𝜃 = 0.5 radians

(~28 deg)

Part 3: Forward Rotation

Input

OutputInput:1. Image2. Theta3. Type of interpolation

Page 57: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

• Solution: Combination of Part 1 and 2

Part 3: Forward Rotation

Page 58: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Idea

x

y

𝜽𝜽

Assuming R is the image obtained after rotation.O

N

Let I be the original image

Page 59: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Idea

x

y

𝜽𝜽

Assuming R is the image obtained after rotation.

1. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image R.1. Determine its location 𝑠𝑠, 𝑗𝑗 before

rotation in the original image

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )

(𝒊𝒊, 𝒋𝒋)

Page 60: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Idea

x

y

𝜽𝜽

Assuming R is the image obtained after rotation.

1. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image R.1. Determine its location 𝑠𝑠, 𝑗𝑗 before

rotation in the original image2. Use neighbors of (𝑠𝑠, 𝑗𝑗) to perform either

nearest neighbour or bilinear interpolation.

3. R 𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ = 𝑠𝑠𝑠𝑠𝑖𝑖𝑖𝑖𝑚𝑚𝑖𝑖𝑖𝑖𝑜𝑜𝑖𝑖𝑖𝑖𝑑𝑑(𝑠𝑠, 𝑗𝑗)

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )

(𝒊𝒊, 𝒋𝒋)

Page 61: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Compute size of rotate image

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image O

N

Let I be the original image

Page 62: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Create Empty Image

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols) O

N

Let I be the original image

Page 63: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Calculate O

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols)5. Calculate location O, with respect to N (𝑂𝑂 =

− min𝑥𝑥, − min𝑦𝑦) (Computed from 4 corners)

O

N

Let I be the original image

Page 64: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Iterate and interpolate

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols)5. Calculate location O, with respect to N (𝑂𝑂 =

− min𝑥𝑥, − min𝑦𝑦)(Computed from 4 corners)6. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2.

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

Page 65: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Iterate and interpolate

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols)5. Calculate location O, with respect to N (𝑂𝑂 =

− min𝑥𝑥, − min𝑦𝑦)(Computed from 4 corners)6. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

𝜃𝜃

(𝒊𝒊, 𝒋𝒋)

Page 66: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Nearest interpolate

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols)5. Calculate location O, with respect to N (𝑂𝑂 =

− min𝑥𝑥, − min𝑦𝑦)(Computed from 4 corners)6. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)3. If using nearest neighbour interpolation

1. nearest neighbour (𝑠𝑠𝑠𝑠𝑠𝑠, 𝑗𝑗𝑠𝑠𝑠𝑠)= (𝑚𝑚𝑜𝑜𝑟𝑟𝑠𝑠𝑑𝑑(𝑠𝑠), 𝑚𝑚𝑜𝑜𝑟𝑟𝑠𝑠𝑑𝑑(𝑗𝑗))2. R 𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ = 𝐼𝐼(𝑠𝑠𝑠𝑠𝑠𝑠, 𝑗𝑗𝑠𝑠𝑠𝑠)

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

𝜃𝜃

(𝒊𝒊, 𝒋𝒋)

Page 67: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Bilinear interpolate

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols)5. Calculate location O, with respect to N (𝑂𝑂 =

− min𝑥𝑥, − min𝑦𝑦)(Computed from 4 corners)6. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)3. If using bilinear interpolation

1. Find four nearest neighbors to (𝑠𝑠, 𝑗𝑗)

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

𝜃𝜃

(𝒊𝒊, 𝒋𝒋)

Page 68: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Bilinear interpolate

x

y

𝜽𝜽

1. Compute Rotation matrix2. Compute Inverse Rotation matrix3. Compute size of the rotated image4. Create rotated image (R) of size (rows, cols)5. Calculate location O, with respect to N (𝑂𝑂 =

− min𝑥𝑥, − min𝑦𝑦)(Computed from 4 corners)6. For (𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ ) in rotated image

1. Calculate location with respect to O𝑠𝑠′ = 𝑠𝑠𝑁𝑁′ − 𝑂𝑂𝑠𝑠 , 𝑗𝑗′ = 𝑗𝑗𝑁𝑁′ − 𝑂𝑂𝑗𝑗

2. Compute inverse rotation on 𝑠𝑠′, 𝑗𝑗′ to get (𝑠𝑠, 𝑗𝑗)3. If using bilinear interpolation

1. Find four nearest neighbors to (𝑠𝑠, 𝑗𝑗)2. perform bi-linear interpolated value (b)2. R 𝑠𝑠𝑁𝑁′ , 𝑗𝑗𝑁𝑁′ = 𝑏𝑏

O

N

Let I be the original image

(𝒊𝒊𝑵𝑵′ , 𝒋𝒋𝑵𝑵′ )(𝒊𝒊′ , 𝒋𝒋′)

𝜃𝜃

(𝒊𝒊, 𝒋𝒋)

Page 69: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Without Interpolation Nearest neighbor Interpolation

Page 70: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment
Page 71: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment
Page 72: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Assignment - 1

1. Forward Rotate (10 Pts.)2. Reverse Rotate (10 Pts)3. Rotate with interpolation (20 Pts)

Total: 40 Pts.Due Date: Oct 1st

Page 73: Assignment -1 - University of Houstonqil.uh.edu/dip/media/cosc6380/Assignment-1.pdf · 1. Resampling Write an algorithm for resampling using nearest neighbor and bi-linear . Assignment

Submission Instructions

• Must use the starter code available in Github• Submission allowed only through Github• You will receive an email with invitation to join Github classroom• Start by reading the readme.md file.• Instructions are available here• Github will automatically save the last commit as a submission

before the deadline