Каркас из изображения с помощью matplotlib - PullRequest
1 голос
/ 08 марта 2020

Я пытаюсь создать трехмерное представление изображения в виде поверхности с использованием каркасов с помощью matplotlib.

ig= mpimg.imread('testIMG.png');
X = np.linspace(0,len(ig[0]),len(ig[0])); #List of discrete x values
Y = np.linspace(0,len(ig[1]),len(ig[1])); #List of discrete y values

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

#Plot the wireframe
#I want to plot the image as f(x,y) and I can't understand why wireframe won't let me

ax.plot_wireframe(X, Y, ig[:,:,2], rstride=10, cstride=10)
plt.show()

Функция imread дает мне массив MxNx3 из M строк, N столбцов и RGB значение для каждой точки в матрице. Я не понимаю, как использовать каркас, чтобы правильно построить эти данные. Эти значения z показывают не то, что я ожидал (рисунок шахматной доски), а вместо этого линию ay = x, чередующуюся от 0 до 1.

Что мне нужно здесь сделать? Я хочу серию кубоидов в 3D шахматном порядке. Изображение того, что у меня сейчас

1 Ответ

0 голосов
/ 08 марта 2020

Вы можете использовать np.meshgrid(), поэтому:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import mpl_toolkits.mplot3d

ig = mpimg.imread('testIMG.png')
x = np.linspace(0, ig.shape[1], ig.shape[1]) #List of discrete x values
y = np.linspace(0, ig.shape[0], ig.shape[0]) #List of discrete y values

X, Y = np.meshgrid(x, y)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

#Plot the wireframe
#I want to plot the image as f(x,y) and I can't understand why wireframe won't let me

ax.plot_wireframe(X, Y, ig[:,:,2], rstride=10, cstride=10)

plt.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...