Pythonのノイズライブラリ内のパーリンノイズ

MS103:

私は私のプロジェクトのためにパーリンノイズを発生して問題を抱えています。私は適切にライブラリを使用する方法を理解したかったように、私は、ステップバイステップのこのページに従ってみました:https://medium.com/@yvanscher/playing-with-perlin-noise-generating-realistic-archipelagos-b59f004d8401 で、コードは、最初の部分があります:

import noise
import numpy as np
from scipy.misc import toimage

shape = (1024,1024)
scale = 100.0
octaves = 6
persistence = 0.5
lacunarity = 2.0

world = np.zeros(shape)
for i in range(shape[0]):
    for j in range(shape[1]):
        world[i][j] = noise.pnoise2(i/scale, 
                                    j/scale, 
                                    octaves=octaves, 
                                    persistence=persistence, 
                                    lacunarity=lacunarity, 
                                    repeatx=1024, 
                                    repeaty=1024, 
                                    base=0)

toimage(world).show()

私はコピー&ペースト終わりに小さな変更でそれを私が持っているので(toimageが廃止されました):

import noise
import numpy as np
from PIL import Image

shape = (1024,1024)
scale = 100
octaves = 6
persistence = 0.5
lacunarity = 2.0
seed = np.random.randint(0,100)

world = np.zeros(shape)
for i in range(shape[0]):
    for j in range(shape[1]):
        world[i][j] = noise.pnoise2(i/scale,
                                    j/scale,
                                    octaves=octaves,
                                    persistence=persistence,
                                    lacunarity=lacunarity,
                                    repeatx=1024,
                                    repeaty=1024,
                                    base=seed)

Image.fromarray(world, mode='L').show()

私はdiffrientモードの多くを試みたが、このノイズは似ても似つかコヒーレントノイズにではありません。私の結果は次のようなものである。この(モード=「L」)。誰かが私が間違って何をやっている、私に説明してもらえますか?

AlexNe:

ここでは、作業コードがあります。私は少しそれをクリーンアップするの自由を取りました。詳細についてはコメントを参照してください。可視化のためのコードをテストし、使用matplotlibの:最後のアドバイスとして。そのimshow()機能は、以下の方法より堅牢ですPIL

import noise
import numpy as np
from PIL import Image

shape = (1024,1024)
scale = .5
octaves = 6
persistence = 0.5
lacunarity = 2.0
seed = np.random.randint(0,100)

world = np.zeros(shape)

# make coordinate grid on [0,1]^2
x_idx = np.linspace(0, 1, shape[0])
y_idx = np.linspace(0, 1, shape[1])
world_x, world_y = np.meshgrid(x_idx, y_idx)

# apply perlin noise, instead of np.vectorize, cosider using itertools.starmap()
world = np.vectorize(noise.pnoise2)(world_x/scale,
                        world_y/scale,
                        octaves=octaves,
                        persistence=persistence,
                        lacunarity=lacunarity,
                        repeatx=1024,
                        repeaty=1024,
                        base=seed)

# here was the error: one needs to normalize the image first. Could be done without copying the array, though
img = np.floor((world + .5) * 255).astype(np.uint8) # <- Normalize world first
Image.fromarray(img, mode='L').show()

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=4578&siteId=1