python - Perlin noise looks too griddy -


i've written own perlin library , have used 1 of standard python libs generating noise. code have bellow:

import sys noise import pnoise2, snoise2  perlin = np.empty((sizeofimage,sizeofimage),dtype=np.float32) freq = 1024 y in range(256):     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') 

the image generates is:enter image description here

regardless of frequency or octaves, looks gritty. conclusion using wrong, i'm not sure why solution wrong. use fractional units via frequency , iterate through 2d array. i've tried switching indicies , not, still there doesn't seem continuity. how can smooth perlin noise?

i think there few potential issues

  • don't convert int before normalising range unless want lose precision
  • to normalise, subtract min max , perlin instead of adding abs(min)

for example:

import numpy np pil import image import sys noise import pnoise2, snoise2  sizeofimage = 256  perlin = np.empty((sizeofimage,sizeofimage),dtype=np.float32) freq = 1024 y in range(256):     x in range(256):         perlin[y][x] = pnoise2(x / freq, y / freq, 4) # don't need scale or shift here code below undoes 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 int here instead img.save('my.png') 

enter image description here


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -