In [1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
def plot_image_from_array(image_array, title=''''Image''''):
plt.imshow(image_array, cmap=''''gray'''')
plt.axis(''''off'''') # Hide axes
plt.title(title)
plt.show()
image = cv2.imread(''''Sharbat_Gula.jpg'''')
#rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, bw_image = cv2.threshold(gray_image, 128, 255, cv2.THRESH_BINARY)
plot_image_from_array(gray_image, title=''''Grayscale'''')
plot_image_from_array(bw_image, title=''''Black and White Image'''')