image_output_1.png
import cv2

import matplotlib.pyplot as plt

img = cv2.imread('/kaggle/input/brain-tumor-mri-images-44c/Carcinoma T2/112._big_gallery.jpeg')
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
threshold_value = 70
max_value = 255
threshold_type = cv2.THRESH_BINARY
_, binary_img = cv2.threshold(gray_img, threshold_value, max_value, threshold_type)

plt.figure(figsize=(12, 5))
plt.title('Pixel Value Distribution')
plt.subplot(1, 2, 1)
plt.hist(gray_img.ravel(), 256, [0, 256])
plt.axvline(x=threshold_value, color='r')
plt.title('Grayscale Image')
plt.subplot(1, 2, 2)
plt.hist(binary_img.ravel(), 256, [0, 256])
plt.title('Binarized Image')
plt.suptitle('Pixel Value Distribution', fontsize=20)
plt.show()