Thursday, July 3, 2025

Draw image profile

 import cv2

import numpy as np

import matplotlib.pyplot as plt

image = cv2.imread('your_image.jpg', cv2.IMREAD_GRAYSCALE)

row = image.shape[0] // 2 # Middle row

profile = image[row, :] # Intensity values along that row

image_with_line = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)

cv2.line(image_with_line, (0, row), (image.shape[1], row), (0, 0, 255), 1)

cv2.imshow("Image with Profile Line", image_with_line)

plt.figure(figsize=(10, 4))

plt.title(f'Intensity Profile of Row {row}')

plt.plot(profile, color='black')

plt.xlabel('Column Index')

plt.ylabel('Intensity')

plt.grid(True)

plt.tight_layout()

plt.show()

cv2.waitKey(0)

cv2.destroyAllWindows()

No comments:

Post a Comment

SD Card vs SSD: What’s Really Happening Inside Your Storage

  We use SD cards in phones and cameras, and SSDs in laptops and PCs, almost without thinking. They both feel similar—fast, silent, and com...