import numpy as np
from mayavi import mlab
from PIL import Image
def display_background_image(image_path):
# Load the image
img = Image.open(image_path)
# Convert the image to grayscale if it is not already
if img.mode != 'L':
img = img.convert('L')
# Convert the image to a NumPy array
img_array = np.array(img)
# Print the shape of the image array
print(f"Image shape: {img_array.shape}")
# Display the image using mlab.imshow
mlab.imshow(img_array, extent=[0, img_array.shape[1], 0, img_array.shape[0], -1, 1])
# Show the figure
mlab.show()
# Example usage
image_path = r"C:\Users\Administrator\Pictures\pinije\20240518090447.png"
display_background_image(image_path)
02-09
2986
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)