import cv2
import matplotlib.pyplot as plt

image=cv2.imread('photo.jpg',cv2.IMREAD_GRAYSCALE)
threshold,otsu_image=cv2.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
plt.imshow(image,cmap="gray")
plt.title("Original Grayscale Image")
plt.axis("off")
plt.subplot(1,2,2)
plt.imshow(otsu_image,cmap="gray")
plt.title("Otsu Thresholded Image")
plt.axis("off")
plt.show()
print("Otsu Threshold Value:",threshold)