使用 Python 和 NumPy 生成批量的 n 维 Perlin 噪声
我设法掌握了 Perlin 噪声的工作方式,并使用 这个很棒的 PDF 作为参考,但是,很明显它非常慢。
首先的想法是批量生成它 - 而不是遍历从 0.0 到 1.0 的每个像素,生成一个 numpy.linspace ,然后使用 numpy 的矢量化操作对其进行操作,但这似乎超出了我的范围,我总是迷失方向并删除我写的所有内容。
好心的 StackOverflower 可以帮助我吗?尽可能少的示例代码和尽可能多的每个步骤的详细解释都会对我有很大帮助。
编辑:所谓批次,是指包含空间中不同点的柏林噪声值的数组,而不是我的noise()方法一次仅生成一个像素。
I managed to grasp the way Perlin noise works and implement a pixel-at-a-time version using this awesome PDF as a reference, but, quite obviously it's incredibly slow.
First thought would be to generate it as batches - instead going through every pixel from 0.0 to 1.0, generate a numpy.linspace
and then act on it using numpy's vectorised operations, but this seems to be beyond me, I keep getting lost and deleting everything I wrote.
Could a kind StackOverflower help me? As little as example code and as much as detailed explanation of every step would both help me greatly.
EDIT: By batches I mean arrays containing values of perlin noise at different points in space, as opposed to my noise() method only generating one pixel at a time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果猜对了,阿斯马吉顿想要预先计算他的噪声纹理,然后将它们绘制到其他不同大小的目标上。
一种方法是使用 scipy.signal.resample< /a> 可以对信号进行插值和二次采样。根据记忆,它一次只能在一个维度上工作——只需循环维度即可。
可能有更好的方法来进行抗锯齿,但这个方法很简单。
If guess correctly, then Asmagedon wants to per-calculate his noise textures and then later paint them onto some other target of a different size.
One way to do this is with scipy.signal.resample which can both interpolate and subsample a signal. From memory it only works on one dimension at a time -- just loop over the dimensions.
There are probably better ways to do antialiasing, but this one is easy.