import cv2 import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Load grayscale image image = cv2.imread('./Castle01.jpg', cv2.IMREAD_GRAYSCALE) # Optional: Resize for speed # image = cv2.resize(image, (128, 128)) # Create coordinate grid x = np.arange(image.shape[1]) y = np.arange(image.shape[0]) X, Y = np.meshgrid(x, y) # Plot fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d') ax.plot_surface(X, Y, image, cmap='gray', edgecolor='none') # Optional: set initial view angle ax.view_init(elev=60, azim=45) ax.set_title('3D Image Intensity') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Intensity') plt.tight_layout() plt.show()