我有以下生成分形图像的代码,
import numpy as np
import matplotlib.pyplot as plt
def julia(C):
X = np.arange(-1.5, 1.5, 0.2)
Y = np.arange(-1.5, 1.5, 0.2)
pixel = np.zeros((len(Y), len(X)))
for x_iter, x in enumerate(X):
for y_iter, y in enumerate(Y):
z = x + 1j * y
intensity = np.nan
r = np.empty((100, 100)) # Unused at the moment
for n in range(1, 1024):
if abs(z) > 2:
intensity = n
break
z = z**2 + C
pixel[y_iter, x_iter] = intensity
r.fill(intensity) # Unused at the moment
# We return pixel matrix
return pixel
# Compute Julia set image
pixel = julia(-0.7 + 0.27015j)
# Plotting
print(pixel[:,:])
数据(像素)如下:
array([[ 1., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2.],
[ 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2.],
[ 2., 2., 2., 2., 2., 2., 2., 3., 3., 3., 3.,
3., 2., 2., 2.],
[ 2., 2., 2., 2., 3., 3., 3., 4., 5., 4., 4.,
3., 3., 3., 2.],
[ 2., 2., 3., 3., 3., 4., 4., 7., 209., 6., 5.,
4., 4., 3., 3.],
[ 2., 3., 3., 3., 4., 5., 6., 37., 59., 220., 13.,
7., 10., 6., 4.],
绘制数据(像素)后,它看起来像
plt.axis('off')
plt.imshow(pixel)
拿到图片后我做了plt.savefig(),当我做image.open()的时候,数据变成了下面这样!我需要摆脱所有这些 255 强度对应的边界不需要的空白
芜湖不芜
相关分类