Jump to content

2nd variation on Perlin Noise (with Python code)

Michael Lee

Recommended Posts

One of the disadvantage of the first variation I tried was that the resizing is naturally tied to the grid of pixels of the image.

Therefore, I figured out a similar idea without this artifact. Although the pictures (with pseudorandom noise) are not quite as cool, it does have a very "fractally" nature to it.





# Original author: Michael S. Lee
# Date: 9/18/2021

import numpy as np
import imageio
import cv2
from scipy.signal import convolve,get_window
import matplotlib.pyplot as plt

def shrink(x, gamma = 30):
    beta = gamma / (x.std())
    y = 1.0 / (1.0 + np.exp(-beta*(x-x.mean())))
N = 1024 # Image size

noise = np.random.rand(N,N,3) # White noise in RGB channels
noise2 = np.copy(noise) # setup output array
noise2 = cv2.resize(noise2,(1024,1024))
noise2 = noise
image = noise2

blur = np.copy(image)
sum1 = np.zeros_like(image)
thresh = 0.375

i = 1024

num_levels = 19
factor = 3/4

for j in range(num_levels):
   blur2 = blur
   ii = ((i+1) // 2) * 2
   blur = cv2.GaussianBlur(noise2, (ii-1,ii-1), 0) #convolve(noise2,kernel3,'same')
   if (j > 0):
     diff = blur - blur2
     diff = shrink(diff, gamma = 25)
     sum1 = sum1 + (i**0.25)*diff 
   #sum1 = sum1 + diff
   print (i)
   i = int(i * factor)
sum1 = (sum1 - sum1.min())/ (sum1.max()-sum1.min())
sum1 = sum1 ** 3

# Save on disk
index = np.random.randint(0,262144) # Random filename


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.