Lab 13

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Artificial To Implement Basic Image Processing Application IIEE

Intelligence
7th Semester Institute of Industrial Electronics Engineering LAB 13

Objective:
The objective of this lab is to introduce undergraduate students to image processing techniques using
Python and OpenCV. Students will learn to perform tasks such as image loading, resizing, and applying
basic filters. By the end of the lab, students should be able to understand the fundamentals of image
processing and build a simple image processing application.

Description:
Image processing is a crucial aspect of computer vision. In this lab, students will develop an image
processing application that allows them to load images, resize them, and apply basic filters such as
grayscale conversion and edge detection.

Steps:
1. Introduction to Image Processing:
• Brief overview of image processing and its applications.

• Introduction to the OpenCV library.

2. Setting Up the Environment:


• Install OpenCV library.

• Provide sample images for testing.

3. Image Loading and Display:


• Load an image using OpenCV.

• Display the original image.

4. Resizing Images:
• Learn to resize images using OpenCV.

• Discuss the importance of image resizing in various applications.

5. Grayscale Conversion:
• Implement grayscale conversion of the loaded image.

• Discuss the advantages of working with grayscale images.

6. Edge Detection:
• Apply edge detection filters to identify prominent edges in the image.
• Discuss the significance of edge detection in image analysis.

7. Interactive Application:
• Create a simple interface allowing users to load an image, resize it, convert it to grayscale,
and apply edge detection.

8. Discussion and Analysis:


• Discuss the impact of various image processing techniques on the visual appearance of
the image.

• Explore potential real-world applications of the developed image processing skills.


Python code:
# Install required library

# pip install opencv-python

# Import necessary libraries

import cv2

import matplotlib.pyplot as plt

# Function to load and display an image

def load_and_display_image(image_path):

img = cv2.imread(image_path)

img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

plt.imshow(img_rgb)

plt.title("Original Image")

plt.axis('off')

plt.show()

# Function to resize an image

def resize_image(image_path, scale_percent):

img = cv2.imread(image_path)

width = int(img.shape[1] * scale_percent / 100)

height = int(img.shape[0] * scale_percent / 100)

resized_img = cv2.resize(img, (width, height))

plt.imshow(resized_img)

plt.title("Resized Image")

plt.axis('off')

plt.show()

# Function to convert an image to grayscale


def convert_to_grayscale(image_path):

img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

plt.imshow(img, cmap='gray')

plt.title("Grayscale Image")

plt.axis('off')

plt.show()

# Function to apply edge detection

def edge_detection(image_path):

img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

edges = cv2.Canny(img, 100, 200)

plt.imshow(edges, cmap='gray')

plt.title("Edge Detection")

plt.axis('off')

plt.show()

# Example usage

image_path = 'path/to/your/image.jpg'

load_and_display_image(image_path)

resize_image(image_path, 50)

convert_to_grayscale(image_path)

edge_detection(image_path)

Note: Replace 'path/to/your/image.jpg' with the actual path to your image file.

This lab is designed to provide students with a practical understanding of basic image processing
techniques using Python and OpenCV. The interactive application allows students to experiment with
different image processing tasks and observe the effects in real-time.

You might also like