用放大器框选目标区域,显示像素灰度值
import matplotlib.pyplot as plt
from PIL import Image
# Open the original image
original_image = Image.open("E:/1.bmp")
# Convert the original image to grayscale
grayscale_image = original_image.convert("L")
# Get the size of the grayscale image
width, height = grayscale_image.size
# Create a list to store the grayscale values
gray_values = []
# Iterate over each pixel in the grayscale image
for y in range(height):
row = []
for x in range(width):
# Get the grayscale value of the pixel
gray_value = grayscale_image.getpixel((x, y))
row.append(gray_value)
gray_values.append(row)
# Create a grid plot of the grayscale values
plt.imshow(gray_values, cmap='gray', interpolation='nearest')
plt.colorbar()
# Show the plot
plt.show()