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

Title: Image Operation and Transformation Objective

The document outlines objectives and procedures for performing image operations and transformations, including addition, subtraction, masking, and geometric manipulations like translation and rotation using Python and OpenCV. It also covers histogram analysis techniques such as histogram equalization and stretching to enhance image contrast and brightness. The conclusions highlight the importance of these techniques in various applications like object detection and medical imaging.

Uploaded by

Sonia khatun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Title: Image Operation and Transformation Objective

The document outlines objectives and procedures for performing image operations and transformations, including addition, subtraction, masking, and geometric manipulations like translation and rotation using Python and OpenCV. It also covers histogram analysis techniques such as histogram equalization and stretching to enhance image contrast and brightness. The conclusions highlight the importance of these techniques in various applications like object detection and medical imaging.

Uploaded by

Sonia khatun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Title: Image Operation and Transformation

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.

Apparatus / Software Used:

- Python with OpenCV

- Computer with required software installed

- Sample grayscale and color images

Theory

Image operations refer to arithmetic and logical manipulations performed on pixel values. These

include:

- Addition/Subtraction: Combining two images or enhancing image intensity.

- Masking: Applying a binary mask to isolate parts of the image.

Image transformations involve geometric manipulation of images:


- Translation: Shifting image position.

- Scaling: Resizing image dimensions.

- Rotation: Rotating image around a center point.

- Flipping: Reversing the image across horizontal or vertical axes.

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:

Original Image Translated Image

Scaled Image Rotated Image(45’)

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.

Apparatus / Software Used

 Python with OpenCV (cv2), NumPy, and Matplotlib


 Jupyter Notebook / any Python IDE
 Sample grayscale image

Theory:

A histogram shows how pixel intensities are distributed in an image.

 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

# Load grayscale image


image = cv2.imread('your_image.jpg', cv2.IMREAD_GRAYSCALE)

# Histogram Equalization
equalized = cv2.equalizeHist(image)

# Stretching: contrast adjustment manually


min_val = np.min(image)
max_val = np.max(image)
stretched = ((image - min_val) / (max_val - min_val) * 255).astype(np.uint8)

# 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')

# Equalized Image and Histogram


plt.subplot(3, 2, 3)
plt.imshow(equalized, cmap='gray')
plt.title('Equalized Image')
plt.axis('off')

plt.subplot(3, 2, 4)
plt.hist(equalized.ravel(), bins=256, range=[0,256])
plt.title('Histogram After Equalization')

# Stretched Image and Histogram


plt.subplot(3, 2, 5)
plt.imshow(stretched, cmap='gray')
plt.title('Stretched Image')
plt.axis('off')

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.

 Histogram Equalization improved contrast in low-contrast images.


 Histogram Stretching made full use of the intensity range.
By comparing histograms before and after these operations, we clearly observed the improvements in
image quality. These techniques are crucial in many applications including medical imaging, satellite
image analysis, and computer vision preprocessing.

You might also like