我現在在寫一個程式主要是要把png輸入後轉換成點,再用散佈圖畫在三維空間坐標系統。現在的問題是我有些點是透明的,但參數C只有黑白,目前想到的方法是把那些alpha為零的點直接刪掉,但是因為這跟整個座標系統會連動不知道該怎麼辦,求大神幫忙!
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=100) # create a figure which size = 20*8 & dpi = 100
ax = fig.add_subplot(111, projection='3d') #set up for graph
img = Image.open('Baby.gnu-alpha-800x800.png') #set the path of graph
pix = img.load()
width = img.size[0]
height = img.size[1]
# set up the size of x,y,z axis
x = np.arange(0,width) # x-axis from 0~800
y = np.arange(0,height)
x,y = np.meshgrid(x,y)
z = np.zeros(width*height)
color = []
for i in range(width):
for j in range(height):
# make every pix into graph
rgb= tuple(np.array(img.getpixel((i,j)))/255)
# print(rgb)
color.append(rgb)
# print(color)
# make a graph at z=0,you can change the value of z to control the height that graph show
ax.scatter(x,y,z,c = color,alpha = 1)
plt.show()