- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
之前,我使用 turtle 在 python 中创建了一个 Mandelbrot 生成器。现在,我正在重新编写程序以使用 Python 图像库,以提高速度并减少对图像大小的限制。
然而,下面的程序只输出RGB废话,几乎是噪声。我认为这与 NumPy 和 PIL 处理数组的方式不同有关,因为说 l[x,y] = [1,1,1]
where l = np .zeros((height,width,3))
当 img = Image.fromarray(l)
和 时,不会 仅使 1 个像素变白img.show()
被执行。
def imagebrot(mina=-1.25, maxa=1.25, minb=-1.25, maxb=1.25, width=100, height=100, maxit=300, inf=2):
l,b = np.zeros((height,width,3), dtype=np.float64), minb
for y in range(0, height):
a = mina
for x in range(0, width):
ab = mandel(a, b, maxit, inf)
if ab[0] == maxit:
l[x,y:] = [1,1,1]
#if ab[0] < maxit:
#smoothit = mandelc(ab[0], ab[1], ab[2])
#l[x, y] = colorsys.hsv_to_rgb(smoothit, 1, 1)
a += abs(mina-maxa)/width
b += abs(minb-maxb)/height
img = Image.fromarray(l, "RGB")
img.show()
def mandel(re, im, maxit, inf):
z = complex(re, im)
c,it = z,0
for i in range(0, maxit):
if abs(z) > inf:
break
z,it = z*z+c,it+1
return it,z,inf
def mandelc(it,z,inf):
return (it+1-log(log(abs(z)))/log(2))
更新 1:
我意识到这个程序中的主要错误之一(我敢肯定有很多)是我使用 x,y 坐标作为复数系数!所以,0 到 100 而不是 -1.25 到 1.25!我已经更改了它,以便代码现在使用变量 a、b 来描述它们,并以我从 turtle 版本中的一些代码中窃取的方式递增。上面的代码已相应更新。由于平滑着色算法代码目前已被注释掉以供调试,因此 inf
变量的大小已减小到 2
。
更新 2:
我在一位优秀用户的帮助下编辑了 numpy 索引。当设置为 200 x 200 时,程序现在输出:
如您所见,它确实显示了一些数学形状,但充满了所有这些奇怪的红色、绿色和蓝色像素!为什么这些会在这里?我的程序只能将 RGB 值设置为 [1,1,1]
或将其保留为默认值 [0,0,0]
。它不能是 [1,0,0]
或类似的东西 - 这一定是一个严重的缺陷...
更新 3:
我认为 NumPy 和 PIL 的集成存在错误。如果我制作 l = np.zeros((100, 100, 3))
然后声明 l[0,0,:] = 1
最后 img = Image.fromarray(l)
& img.show()
,这就是我们得到的:
这里我们得到了一系列彩色像素。 这需要另一个问题。
更新 4:
我不知道之前发生了什么,但似乎对于 np.uint8
数组,Image.fromarray()
使用 0-255 的颜色值。有了这一点智慧,我离理解这个曼德尔虫又近了一步!
现在,我确实得到了一些模糊的数学结果,但它仍然输出奇怪的东西。
这个点就是全部...如果我更改为 np.uint16
,我会得到更奇怪的东西,我推测是由于不同的字节形状和编码方案。
最佳答案
你对 3D 数组 l 的索引不正确,试试
l[x,y,:] = [1,1,1]
相反。有关如何访问和修改 numpy 数组的更多详细信息,请查看 numpy indexing
作为旁注:quickstart documentation numpy 实际上有一个 mandelbrot 集生成和绘图的实现。
关于python - 使用 NumPy 和 Pillow 绘制 Mandelbrot 时,程序输出明显的噪音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41524343/
我今天尝试使用噪声在处理中生成伪随机角度,但它没有像我希望的那样工作。 float xoff = 0; float inc = 0.01; void draw(){ float vx = cos(
我正在使用 OpenCV 和 Python 处理图像。我需要去除图像中的点/噪声。 我尝试了使点变小的膨胀,但是文本被损坏了。我还尝试了两次循环扩张和一次腐 eclipse 。但这并没有给出令人满意的
我需要使用我编写的 perlin 噪声程序在 Java 中生成 3D 行星(球体)的纹理。但问题是左侧和右侧需要相同,上下也必须相同,这样您才能将纹理放在球体上。 我无法将柏林噪声源放在这里,因为它太
我想构建一个 android 应用程序,它可以识别我的声音,将其转换为文本,并显示我刚刚说的 toast 。我可以通过使用一个按钮来为我启动语音识别器来做到这一点。但现在我想让它只根据我的声音工作。
嗨,我正在使用我发现的算法来生成柏林噪声。我想做的是用更少的曲线创建更锐利的边缘Picture 。 private static final double F2 = 0.5*(Math.sqr
我正在尝试用 C++ 编写一个程序来播放一个小的 .wav 文件。我已经按照 DirectX SDK 文档对其进行了编程,以在辅助静态缓冲区上编写和播放。它运行正常,除了在任何 .wav 文件播放结束
在这个 short video 中听我的问题. 现在我更详细地解释: 在那个视频中,我已经播放了(点击按钮)一个音频文件三次,连续两次,最后一次有一点停顿。第一次听起来像 radio 正在调谐,第二次
所以在过去的几个小时里,我一直在尝试用 Dart 制作一个简单的 Perlin 噪声发生器。为此,我决定在 this page 上使用二维生成的伪代码。 (很棒的阅读!) 这是我的 Dart 实现的样
我正在为 android 开发一个 OCR 应用程序(构建为 java 应用程序)。我想从相机捕获的图像中检测文本并进行预处理我正在使用 OpenCV,但我得到了一些额外的行,这些行被读取为文本,我采
我正在使用 Ruby on Rails 3.1.1 和 pg gem。 在我的 Gemfile.lock 中,这是我拥有的 pg (0.11.0) 我的日志中充满了如下所示的信息。我没有用 sqlit
我在 javascript 中创建了一个带有实时对话模块的应用程序。我正在使用 WebRTC 设置对等连接。信号和候选人似乎都工作正常。对等点不在同一个网络上。 在某些时候,音频开始向流中添加点击。质
我在基于 android 的 csipsimple 应用程序中使用了一个 PJSIP 库。除一个问题外,一切正常。当我打开扬声器时,通话中有很多回声/噪音,无法进行通话。可能是什么问题以及如何处理这个
当您按下 alt+几乎任何其他键时,它会发出 clang 。噪音说“你已经尝试做一些你做不到的事情” 我想在多个组合中使用 alt 键作为网络应用程序的键盘快捷键。 尽管在按下 alt+* 时有一些事
我的目标是创建一个 SDL 窗口,绘制不同的波形并播放该波的不确定声音。通过按下特定的键,可以修改波的幅度、频率或波形等参数。 问题在于,即使是绘制时看起来不错的简单正弦波,听起来也很嘈杂。我不明白为
我收到大量这样的消息,围绕着我故意不支持的 SSL 协议(protocol),例如SSLv3、TLS1.0 等 2020-02-06 13:08:30,600 ERROR [io.undertow.r
我有错误s的情况通常是从 3rd-party JS 发出的,例如 Chartbeat 等。我想捕获并丢弃/静音这些错误以及相关的噪音。 所有此类 3rd 方脚本都会执行以下操作: 创建 DOM 标签
我对新 ffmpeg 中的重采样结果感到困惑。我将 AAC 音频解码为 PCM,ffmpeg 显示音频信息为: Stream #0:0: Audio: aac, 44100 Hz, stereo, f
我是一名优秀的程序员,十分优秀!