Jump to content

A fun little variation on Perlin noise (with Python code)


Recommended Posts

I was experimenting with Perlin-like (I call it Perloid) noise when I realized I could threshold a little bit harder than usual.

The first few images are "regular" sort of Perlin-like, but as you get 5-9, the thresholding is increase for each color channel and resolution channel. It ends producing almost natural-like features. It is it ITC, mathematics in action, or both?

perloid_set.png

Code: 

#---------------------------------
# Original author: Michael S. Lee
# Date: 8/27/2021
#---------------------------------

import numpy as np
import matplotlib.pyplot as plt
import cv2

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

image = noise2
blur = np.copy(image)
sum1 = np.zeros_like(image)

for j,i in enumerate([512,256,128,64,32,16,8,4,2]):

   image = cv2.resize(noise2,(i,i),interpolation=cv2.INTER_LANCZOS4)
   blur2 = blur
   blur = cv2.resize(image,(N,N))
   diff = blur - blur2
   min1 = diff.mean() - 1.0*diff.std()
   max1 = diff.mean() + 1.0*diff.std()
   diff = np.clip((diff - min1)/(max1-min1),0,1)
   sum1 = sum1 + (j+1)*diff

min1 = sum1.mean() - 2.0*sum1.std()
max1 = sum1.mean() + 2.0*sum1.std()

sum1 = np.clip((sum1 - min1) / (max1-min1),0,1)
plt.imshow(sum1)

plt.show()

 

Link to comment
Share on other sites

Wow! At least you found a way to create impressionist art with a mouseclick. Relly fascinating!. Picture 7 in your first posting is my favorite one, there are clearl shapes showing up -a bit like cubism. But also the last two images are wonderful! I saw similar patterns in reflections in water from trees with leafs in summer.

Could you explain your program in more detail please, specially what parameter defines the threshold?

Link to comment
Share on other sites

In my new version below, thresholding is controlled by "gamma" within the "shrink" function.

Mandatory face pictures 😉 Same person with circular black sunglasses?

face2.jpgface1.jpg

Code version 2 (for record keeping, and others to experiment with):

#---------------------------------
# Original author: Michael S. Lee
# Date: 8/27/2021
#---------------------------------

import numpy as np
import imageio
import cv2

def shrink(x, gamma = 30):
    beta = gamma / (x.std())
    y = 1.0 / (1.0 + np.exp(-beta*(x-x.mean())))
    return(y)
    
N = 1024 # Image size
noise = np.random.rand(N,N,3) # White noise in RGB channels
noise2 = np.copy(noise) # setup output array

image = noise2
blur = np.copy(image)
sum1 = np.zeros_like(image)
thresh = 0.375#375
for j,i in enumerate([512,256,128,64,32,16,8,4]):

   image = cv2.resize(noise2,(i,i),interpolation=cv2.INTER_LANCZOS4)
   blur2 = blur
   blur = cv2.resize(image,(N,N))
   
   diff = blur - blur2
   diff = shrink(diff, gamma = 10)
   sum1 = sum1 + (j+1)*(j+1)*diff
   #sum1 = sum1 + (j+1)*diff
   
min1 = sum1.mean() - 2*sum1.std()
max1 = sum1.mean() + 2*sum1.std()

sum1 = shrink(sum1, gamma=1) 

# Save on disk
index = np.random.randint(0,262144) # Random filename
imageio.imsave('temp.'+str(index)+'.png',sum1)

 

Link to comment
Share on other sites

17 minutes ago, Michael Lee said:

I added a little bit of darkening in my algorithm to make it a little more like itc-station's Perlin images.

Also, I used my microphone to generate 20 seconds of ambient noise and reshape it into a 1024x1024x3 image.

This is the 3rd attempt using ambient noise (192 kHz for 20 seconds):

temp.185384.thumb.png.05f9453a595c6b0272d9428d95bc69cc.png

96 kHz for 40s:

temp.178020.thumb.png.02456fd94b333c266ec732a6fe7ab07c.png

Your last picture is just amazing! It is somehow organic like plants or weed.😲

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.

Guest
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.