DIP FILE-1
DIP FILE-1
# Marker labelling
ret, markers = cv2.connectedComponents(sure_fg)
if img is None:
print("Error: Could not read the image. Please check the image path.")
return
# Plot histogram
plt.figure(figsize=(10, 4))
plt.title('Grayscale Histogram')
plt.xlabel('Bins')
plt.ylabel('# of Pixels')
plt.plot(hist)
plt.xlim([0, 256])
plt.show()
# Convert to RGB
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Calculate histograms for each channel
color = ('r', 'g', 'b')
for i, col in enumerate(color):
hist = cv2.calcHist([image], [i], None, [256], [0, 256])
plt.plot(hist, color=col)
# Plot histogram
plt.title('Color Histogram')
plt.xlabel('Bins')
plt.ylabel('# of Pixels')
plt.xlim([0, 256])
plt.show()
plt.show()
OUTPUT
4