I have searched everywhere for an answer for this question but no luck. I want to figure out how to take the image generated by python's noise library and export it. does anybody know how?
2 Answers
The GitHub repository for the noise library has an examples folder. One of them is an example of how to generate 2D perlin noise and write it to a file.
If you want more standard file formats, such as a PNG or TIFF, you can use Numpy to create an array and write the perlin noise values to the array, and then save the array as an image file using OpenCV.
Comments
Convert your data list to a numpy array then use PIL library to save the numpy array to a grayscale image:
# Install PIL: pip install pillow (probably already installed)
from PIL import Image
import numpy as np
from perlin_noise import PerlinNoise
noise = PerlinNoise(octaves=10, seed=1)
xpix, ypix = 100, 100
pic = [[noise([i/xpix, j/ypix]) for j in range(xpix)] for i in range(ypix)]
image = Image.fromarray(np.array(pic) * 255, 'L')
image.save('output.png')
