exp4j
exp4j
4:
a.)
import cv2
import numpy as np
import matplotlib.pyplot as plt
if image is None:
print(f"❌ Could not read image: {image_path}")
continue
# Compute histogram
hist = cv2.calcHist([image], [0], None, [256], [0, 256])
# Classification
if brightness < 85:
category = "Dark Image"
elif brightness > 170:
category = "Light Image"
elif contrast < 40:
category = "Low Contrast Image"
else:
category = "High Contrast Image"
plt.subplot(1, 2, 1)
plt.imshow(image, cmap='gray')
plt.title(f"Grayscale Image: {image_path.split('/')[-1]}")
plt.axis("off")
plt.subplot(1, 2, 2)
plt.plot(hist, color='black')
plt.title("Histogram")
plt.xlabel("Pixel Value")
plt.ylabel("Frequency")
plt.tight_layout()
plt.show()
import cv2
import numpy as np
import matplotlib.pyplot as plt
if image is None:
print(f"❌ Could not read image: {image_path}")
continue
# Create an array to hold the histogram values (256 bins for pixel values 0 to
255)
hist = np.zeros(256, dtype=int)
plt.subplot(1, 2, 1)
plt.imshow(image, cmap='gray')
plt.title(f"Grayscale Image: {image_path.split('/')[-1]}")
plt.axis("off")
plt.subplot(1, 2, 2)
plt.plot(hist, color='black')
plt.title("Histogram")
plt.xlabel("Pixel Value")
plt.ylabel("Frequency")
plt.tight_layout()
plt.show()
b.)
import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.subplot(2, 2, 2)
plt.plot(hist_before, color='black')
plt.title("Histogram Before Equalization")
plt.xlabel("Pixel Value")
plt.ylabel("Frequency")
plt.tight_layout()
plt.show()
import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.subplot(2, 2, 2)
plt.plot(hist_before, color='black')
plt.title("Histogram Before Equalization")
plt.xlabel("Pixel Value")
plt.ylabel("Frequency")
plt.subplot(2, 2, 4)
plt.plot(hist_after, color='black')
plt.title("Histogram After Equalization")
plt.xlabel("Pixel Value")
plt.ylabel("Frequency")
plt.tight_layout()
plt.show()