Professional Documents
Culture Documents
import numpy as np
import matplotlib.pyplot as plt
if original_image is None:
print("Error: Unable to load the image.")
exit()
plt.subplot(1, 2, 2)
plt.imshow(processed, cmap='gray')
plt.title(processed_name)
plt.axis('off')
plt.show()
# Smoothing
smoothed_image = cv2.GaussianBlur(original_image, (5, 5), 0)
display_images(original_image, smoothed_image, 'Smoothed Image')
# High-boost filtering
k = 1.5 # Boosting factor
high_boost_kernel = np.array([[-1, -1, -1],
[-1, k+8, -1],
[-1, -1, -1]]) / k
high_boost_image = cv2.filter2D(original_image, -1, high_boost_kernel)
display_images(original_image, high_boost_image, 'High-boost Filtered
Image')
# Gradient filtering
sobelx = cv2.Sobel(original_image, cv2.CV_64F, 1, 0, ksize=3)
sobely = cv2.Sobel(original_image, cv2.CV_64F, 0, 1, ksize=3)
gradient_image = np.sqrt(sobelx**2 + sobely**2)
display_images(original_image, gradient_image, 'Gradient Filtered
Image')