AI Project
AI Project
Objective: Analyze temperature data using Pandas and visualize it with Matplotlib.
import pandas as pd
import matplotlib.pyplot as plt
# Convert to DataFrame
df = pd.DataFrame(data)
# Sales data
products = ["Product A", "Product B", "Product C", "Product D"]
sales = [100, 150, 200, 80]
Objective: Convert a grayscale image into a binary image using a threshold value.
import cv2
import matplotlib.pyplot as plt
# Apply thresholding
threshold = 128
_, binary_image = cv2.threshold(image, threshold, 255, cv2.THRESH_BINARY)
plt.subplot(1, 2, 2)
plt.title("Binary Image")
plt.imshow(binary_image, cmap='gray')
plt.axis('off')
plt.show()
Project 4: Simple Image Blurring
import cv2
import matplotlib.pyplot as plt
plt.subplot(1, 2, 2)
plt.title("Blurred Image")
plt.imshow(blurred_image)
plt.axis('off')
plt.show()
Project 5: Edge Detection in an Image
Objective: Detect edges in an image using the Canny Edge Detection algorithm.
import cv2
import matplotlib.pyplot as plt
# Load an image
image_path = "Vaibhav Kumar.jpeg" # Replace with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
plt.subplot(1, 2, 2)
plt.title("Edge Detection")
plt.imshow(edges, cmap='gray')
plt.axis('off')
plt.show()
Project 6: Face Detection Using OpenCV
import cv2
import matplotlib.pyplot as plt
# Detect faces
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1,
minNeighbors=5)
import cv2
import matplotlib.pyplot as plt
plt.subplot(2, 2, 1)
plt.title("Original Image")
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.subplot(2, 2, 2)
plt.title("Red Channel")
plt.imshow(red, cmap='Reds')
plt.axis('off')
plt.subplot(2, 2, 3)
plt.title("Green Channel")
plt.imshow(green, cmap='Greens')
plt.axis('off')
plt.subplot(2, 2, 4)
plt.title("Blue Channel")
plt.imshow(blue, cmap='Blues')
plt.axis('off')
plt.tight_layout()
plt.show()
Project 8: Create a Scatter Plot
Code:
import pandas as pd
import matplotlib.pyplot as plt
# Convert to DataFrame
df = pd.DataFrame(data)
# Scatter plot
plt.figure(figsize=(8, 5))
plt.scatter(df["Age"], df["Marks"], color='purple', label="Marks vs Age")
plt.title("Age vs Marks Scatter Plot")
plt.xlabel("Age")
plt.ylabel("Marks")
plt.legend()
plt.grid()
plt.show()
Project 9: Create a Line Plot of Population Growth
Code:
# Population data
years = [2000, 2005, 2010, 2015, 2020]
population = [6, 6.5, 7, 7.5, 8] # In billions
import cv2
import matplotlib.pyplot as plt
plt.subplot(1, 2, 2)
plt.title("Rotated Image (90° Clockwise)")
plt.imshow(rotated_rgb)
plt.axis('off')
plt.show()