柏林噪音看起来太格朗

柏林噪音看起来太格朗

问题描述:

我已经写了我自己的perlin库,并且还使用了其中一个标准的python库来产生噪音。这是我有波纹管代码:柏林噪音看起来太格朗

import sys 
from noise import pnoise2, snoise2 

perlin = np.empty((sizeOfImage,sizeOfImage),dtype=np.float32) 
freq = 1024 
for y in range(256): 
    for x in range(256): 
     perlin[y][x] = int(pnoise2(x/freq, y/freq, 4) * 32.0 + 128.0) 
max = np.amax(perlin) 
min = np.amin(perlin) 
max += abs(min) 
perlin += abs(min) 
perlin /= max 
perlin *= 255 
img = Image.fromarray(perlin, 'L') 
img.save('my.png') 
dp(filename='my.png') 

它生成的图像是:enter image description here

无论频率还是八度的,它看起来总是坚韧不拔。这是我的结论,因此我错误地使用了它,但我不确定为什么我的解决方案是错误的。我通过频率使用小数单位并遍历我的二维数组。我试过切换标记,但还没有,但仍然没有连续性。我怎样才能获得平稳的珀林噪音?

+0

这是Python2.x吗?如果是这样'x/freq'使用整数除法,并且将循环到零循环中的所有值 –

+0

这是python 3 –

我觉得有几个潜在的问题

  • ,除非你不想失去精度
  • 正常化,减去maxminperlin,而不是添加abs(min)的没有转换为int正火范围之前

例如:

import numpy as np 
from PIL import Image 
import sys 
from noise import pnoise2, snoise2 

sizeOfImage = 256 

perlin = np.empty((sizeOfImage,sizeOfImage),dtype=np.float32) 
freq = 1024 
for y in range(256): 
    for x in range(256): 
     perlin[y][x] = pnoise2(x/freq, y/freq, 4) # don't need to scale or shift here as the code below undoes that anyway 
max = np.amax(perlin) 
min = np.amin(perlin) 
max -= min 
perlin -= min 
perlin /= max 
perlin *= 255 
img = Image.fromarray(perlin.astype('uint8'), 'L') # convert to int here instead 
img.save('my.png') 

enter image description here

+0

我觉得把min转换成abs绝对是我出错的地方。谢谢您的帮助! –