KevinCesarJacobo Exer3
KevinCesarJacobo Exer3
1. Codes
import cv2
import matplotlib.pyplot as plt
I = cv2.imread('sheesh.jpg')
plt.subplot(2, 2, 1)
plt.imshow(cv2.cvtColor(I, cv2.COLOR_BGR2RGB))
plt.title('Original Image')
plt.subplot(2, 2, 2)
plt.imshow(cv2.cvtColor(j, cv2.COLOR_BGR2RGB))
plt.title('Scaled Image')
kangle = 60
rangle = 45
plt.subplot(2, 2, 3)
plt.imshow(cv2.cvtColor(K, cv2.COLOR_BGR2RGB))
plt.title('Rotated Image 60deg')
plt.subplot(2, 2, 4)
plt.imshow(cv2.cvtColor(R, cv2.COLOR_BGR2RGB))
plt.title('Rotated Image 45deg')
plt.show()
import cv2
import matplotlib.pyplot as plt
plt.subplot(2, 2, 1)
plt.imshow(cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB))
plt.title('Original Image')
plt.subplot(2, 2, 2)
plt.imshow(cv2.cvtColor(bilinear_image, cv2.COLOR_BGR2RGB))
plt.title('Bilinear Interpolation')
plt.subplot(2, 2, 3)
plt.imshow(cv2.cvtColor(nearest_image, cv2.COLOR_BGR2RGB))
plt.title('Nearest Neighbor Interpolation')
plt.subplot(2, 2, 4)
plt.imshow(cv2.cvtColor(bicubic_image, cv2.COLOR_BGR2RGB))
plt.title('Bicubic Interpolation')
plt.show()
# 1. Intensity Transformations
# Linear Scaling
a = 1.5
b = 30
linear_scaled_image = np.array(original_image) * a + b
linear_scaled_image = Image.fromarray(np.uint8(linear_scaled_image))
plt.figure(figsize=(10, 10))
plt.subplot(3, 4, 1)
plt.imshow(linear_scaled_image)
plt.title('Linear Scaled Image')
# Logarithmic Transformation
c = 50
log_transformed_image = c * np.log(1 + np.array(original_image))
log_transformed_image = Image.fromarray(np.uint8(log_transformed_image))
plt.subplot(3, 4, 2)
plt.imshow(log_transformed_image)
plt.title('Log Transformed Image')
# Power-law Transformation
gamma = 0.5
power_law_transformed_image = c * (np.array(original_image) ** gamma)
power_law_transformed_image =
Image.fromarray(np.uint8(power_law_transformed_image))
plt.subplot(3, 4, 3)
plt.imshow(power_law_transformed_image)
plt.title('Power-law Transformed Image')
# 2. Spatial Transformations
# Translation
tx = 50
ty = 30
translated_image = original_image.transform(original_image.size,
Image.AFFINE, (1, 0, tx, 0, 1, ty))
plt.subplot(3, 4, 4)
plt.imshow(translated_image)
plt.title('Translated Image')
# Rotation
rotated_image = original_image.rotate(-45, expand=True)
plt.subplot(3, 4, 5)
plt.imshow(rotated_image)
plt.title('Rotated Image 45deg')
# Scaling
scale_factor = 2
scaled_image = original_image.resize((int(original_image.width *
scale_factor), int(original_image.height * scale_factor)))
plt.subplot(3, 4, 6)
plt.imshow(scaled_image)
plt.title('Scaled Image')
# 3. Geometric Transformations
# Affine Transformation
a = 0.5
b = 0.3
c = -0.2
d = 0.8
tx = 50
ty = -20
affine_matrix = (a, b, tx, c, d, ty)
affine_transformed_image = original_image.transform(original_image.size,
Image.AFFINE, affine_matrix)
plt.subplot(3, 4, 7)
plt.imshow(affine_transformed_image)
plt.title('Affine Transformed Image')
# 4. Color Transformations
# Grayscale Conversion
grayscale_image = original_image.convert('L')
plt.subplot(3, 4, 9)
plt.imshow(grayscale_image, cmap='gray')
plt.title('Grayscale Image')
# 6. Histogram Transformations
# Histogram Equalization
equalized_image = ImageOps.equalize(original_image)
plt.subplot(3, 4, 12)
plt.imshow(equalized_image)
plt.title('Histogram Equalized Image')
2. Output
3. Answer the following questions:
A. Intensity Transformations: - Explain the importance of intensity transformations in
image processing. How might linear scaling and logarithmic transformations be used to
enhance features such as terrain or vegetation?
Spatial transformations are important in image analysis as they allow for adjusting the
position, orientation, and size of images to align them or correct for distortions.
Translation, rotation, and scaling can be applied to align images from different passes in
satellite imaging or correct for geometric distortions caused by camera lenses.
Geometric transformations, like affine and projective transformations, play a crucial role
in image processing by allowing for more complex transformations of images. For
example, affine transformations can correct for perspective distortions in aerial images,
while projective transformations (homography) are essential for tasks like panorama
stitching or augmented reality.
Fourier Transform is a powerful tool in image processing that allows for analyzing
images in the frequency domain, helping to identify patterns, anomalies, or
environmental features that may not be easily discernible in the spatial domain. This
technique finds applications in tasks like image compression, image filtering, and
pattern recognition.