Title: Image Operation and Transformation Objective
Title: Image Operation and Transformation Objective
Objective:
1. To understand and apply basic image operations such as image addition, subtraction, and
masking.
2. To perform geometric transformations like translation, scaling, rotation, and flipping on digital
images.
3. To implement and analyze the effects of these operations on image quality and content.
4. To develop hands-on skills in using image processing tools/libraries (e.g., OpenCV or MATLAB).
5. To observe how pixel-wise and spatial operations influence image structure and interpretation.
Theory
Image operations refer to arithmetic and logical manipulations performed on pixel values. These
include:
These transformations are essential in image preprocessing, computer vision tasks, and feature
alignment.
Code:
import cv2
import numpy as np
# Load Image
img = cv2.imread('input.jpg')
# Translation
M = np.float32([[1, 0, 50], [0, 1, 100]])
translated = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))
# Scaling
scaled = cv2.resize(img, None, fx=0.5, fy=0.5)
# Rotation
(h, w) = img.shape[:2]
center = (w // 2, h // 2)
matrix = cv2.getRotationMatrix2D(center, 45, 1.0)
rotated = cv2.warpAffine(img, matrix, (w, h))
# Flipping
flipped = cv2.flip(img, 1) # Horizontal flip
# Display
cv2.imshow("Original", img)
cv2.imshow("Translated", translated)
cv2.imshow("Scaled", scaled)
cv2.imshow("Rotated", rotated)
cv2.imshow("Flipped", flipped)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Flipped Image
Conclusion:
In this lab, we successfully implemented and understood various image operations and
transformations. We observed how simple arithmetic manipulations can alter image appearance and
how geometric transformations are crucial for spatial analysis. These fundamental techniques are
widely used in fields like object detection, medical imaging, remote sensing, and computer vision
applications. Mastering these concepts is essential for building more advanced image processing
systems.
Title:
Objective
1. To understand the concept of histogram in digital images.
2. To analyze how histogram changes with different image operations.
3. To implement histogram equalization and observe its effect on image contrast.
4. To visualize histograms before and after enhancement techniques.
5. To apply histogram stretching and analyze its impact on brightness distribution.
Theory:
Histogram Equalization: Enhances the contrast of images by spreading out intensity values across the
histogram.
Histogram Stretching (Contrast Stretching): Expands the range of intensity values to occupy the full
spectrum (0-255).
Histogram Comparison: Visual comparison before and after enhancements helps evaluate image
quality.
Code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Histogram Equalization
equalized = cv2.equalizeHist(image)
# Displaying images
plt.figure(figsize=(12, 8))
# Original Image and Histogram
plt.subplot(3, 2, 1)
plt.imshow(image, cmap='gray')
plt.title('Original Image')
plt.axis('off')
plt.subplot(3, 2, 2)
plt.hist(image.ravel(), bins=256, range=[0,256])
plt.title('Histogram of Original')
plt.subplot(3, 2, 4)
plt.hist(equalized.ravel(), bins=256, range=[0,256])
plt.title('Histogram After Equalization')
plt.subplot(3, 2, 6)
plt.hist(stretched.ravel(), bins=256, range=[0,256])
plt.title('Histogram After Stretching')
plt.tight_layout()
plt.show()
Output:
Conclusion:
In this lab, we explored how histogram transformations impact image contrast and brightness.