简体   繁体   English

使用Python和NumPy生成批量的n维Perlin噪声

[英]Generating batches of n-dimensional Perlin noise using Python and NumPy

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. 我设法掌握了Perlin噪声的工作方式,并使用这个令人敬畏的PDF作为参考实现了一次一个像素的版本,但是,显然它非常慢。

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. 首先想到的是将它作为批处理生成 - 而是通过每个像素从0.0到1.0,生成一个numpy.linspace然后使用numpy的矢量化操作对它进行操作,但这似乎超出了我,我一直迷路并删除所有内容我写。

Could a kind StackOverflower help me? StackOverflower可以帮帮我吗? 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. 编辑:按批次我的意思是包含空间中不同点的perlin噪声值的数组,而不是我的noise()方法一次只生成一个像素。

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. 如果猜测正确,那么Asmagedon想要计算他的噪声纹理,然后将它们绘制到不同大小的其他目标上。

One way to do this is with scipy.signal.resample which can both interpolate and subsample a signal. 一种方法是使用scipy.signal.resample ,它可以对信号进行插值和子采样。 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. 可能有更好的方法来做抗锯齿,但这个很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM