Input
Input
import cv2
import matplotlib.pyplot as plt
# Load an image using OpenCV
image =
cv2.imread('257803.jpg')
# Convert the image from BGR
to RGB
image_rgb =
cv2.cvtColor(image,
cv2.COLOR_BGR2RGB)
# Display the image using
Matplotlib
plt.imshow(image_rgb)
plt.title('Image Loaded with
OpenCV')
plt.axis('off')
plt.show()
Input: Output:
# Resize an image
image =
cv2.imread('257803.jpg')
resized_image =
cv2.resize(image, (1050, 1610))
Input: Output:
# Convert image to
grayscale
gray_image =
cv2.cvtColor(image,
cv2.COLOR_BGR2GRAY)
Input: Output:
equalized_image =
cv2.equalizeHist(gray_image)
Input: Output:
# Calculate the
histogram of the
equalized image
equalized_hist =
cv2.calcHist([equalized
_
image], [0], None,
[256], [0, 256])
# Plot the histogram of
the equalized image
plt.plot(equalized_hist)
plt.title('Histogram of
Equalized Image')
plt.xlabel('Pixel Value')
plt.ylabel('Frequency')
plt.show()
Input: Output:
# Apply Gaussian blur
blurred_image =
cv2.GaussianBlur(image, (15, 15), 0)
Input: Output:
import numpy as np
Input: Output:
"""**Image Segmentation**"""
plt.imshow(binary_image,
cmap='gray')
plt.title('Binary Image')
plt.axis('off')
plt.show()