Search code examples
pythonimage-processinggaussian

How to create Gaussian Noise texture in python?


I need to create a texture like the below one with the specific key is there any way of creating this using python? Also, I need to extract the texture from another image and compare using this.Basically, the idea is, I will create a texture using Gaussian Noise and I will distribute it.After that when someone sends the texture back to me I want to know whether the texture is same as that i send

Texture image


Solution

  • Just to answer the question asked in the title, here's how you generate and save Gaussian noise texture in Python using numpy and cv2:

    import numpy as np
    import cv2
    
    SHAPE = (150, 200)
    
    noise = np.random.normal(255./2, 255./10, SHAPE)
    cv2.imwrite("gaussian_noise.png", noise)
    

    And using numpy and Pillow:

    import numpy as np
    from PIL import Image
    
    SHAPE = (150, 200)
    
    noise = np.random.normal(255./2, 255./10, SHAPE)
    image = Image.fromarray(noise)
    image = image.convert('RGB')
    image.save("gaussian_noise.png")
    

    Example output:

    Gaussian noise 200 by 150 pixels, mean = 127.5, dev = 25.5

    As to the second part of your question, it's really unclear and ambiguous. You should show your code in order for people on StackOverflow to help you.