How to create a noise pattern on an image using Pillow?

Sep 15, 2025

Leave a message

Michael Brown
Michael Brown
Michael is in charge of the medical equipment factory established in 2018. He has rich knowledge in medical device production and is committed to expanding the company's product line in the medical field.

As a Pillow supplier, I've had numerous inquiries from photographers, graphic designers, and digital artists about creating noise patterns on images using Pillow, a powerful Python library for image processing. In this blog post, I'll guide you through the process of generating noise patterns on an image with Pillow, and also share some tips and tricks along the way.

Understanding Pillow and Its Capabilities

Before we dive into creating noise patterns, let's briefly discuss what Pillow is. Pillow is a fork of the Python Imaging Library (PIL), which provides a wide range of image processing capabilities. It allows you to open, manipulate, and save many different image file formats. You can learn more about Pillow on our official website.

Prerequisites

To follow along with this tutorial, you'll need to have Python installed on your system, along with the Pillow library. You can install Pillow using pip:

17335628263059f54c4f920cf28f75e407089c30353d6Pillow

pip install pillow

Types of Noise Patterns

There are several types of noise patterns that you can create on an image, including:

  • Gaussian Noise: This is the most common type of noise, which follows a Gaussian distribution. It appears as random variations in the image intensity.
  • Salt and Pepper Noise: This type of noise consists of randomly occurring white and black pixels in the image.
  • Poisson Noise: Poisson noise is typically found in images captured with low light or high ISO settings. It follows a Poisson distribution.

Creating Gaussian Noise Pattern

Let's start by creating a Gaussian noise pattern on an image. Here's the Python code to achieve this:

from PIL import Image
import numpy as np

# Open the image
image = Image.open('your_image.jpg')

# Convert the image to a NumPy array
image_array = np.array(image)

# Generate Gaussian noise
mean = 0
std = 20
noise = np.random.normal(mean, std, image_array.shape).astype(np.uint8)

# Add the noise to the image
noisy_image_array = image_array + noise

# Clip the values to the valid range (0-255)
noisy_image_array = np.clip(noisy_image_array, 0, 255).astype(np.uint8)

# Convert the NumPy array back to an image
noisy_image = Image.fromarray(noisy_image_array)

# Save the noisy image
noisy_image.save('noisy_image.jpg')

In this code, we first open the image using Image.open(). Then, we convert the image to a NumPy array so that we can perform numerical operations on it. We generate Gaussian noise using np.random.normal() and add it to the image array. Finally, we clip the values to the valid range (0-255) and convert the NumPy array back to an image using Image.fromarray().

Creating Salt and Pepper Noise Pattern

Now, let's create a salt and pepper noise pattern on an image. Here's the Python code:

from PIL import Image
import numpy as np

# Open the image
image = Image.open('your_image.jpg')

# Convert the image to a NumPy array
image_array = np.array(image)

# Define the probability of salt and pepper noise
prob = 0.01

# Generate a random matrix with the same shape as the image
random_matrix = np.random.rand(*image_array.shape)

# Create salt and pepper noise
salt = (random_matrix > 1 - prob) * 255
pepper = (random_matrix < prob) * 0

# Add the noise to the image
noisy_image_array = image_array.copy()
noisy_image_array[salt > 0] = 255
noisy_image_array[pepper > 0] = 0

# Convert the NumPy array back to an image
noisy_image = Image.fromarray(noisy_image_array)

# Save the noisy image
noisy_image.save('salt_and_pepper_noisy_image.jpg')

In this code, we generate a random matrix with the same shape as the image using np.random.rand(). We then create salt and pepper noise by setting the pixels to 255 or 0 based on the probability threshold. Finally, we add the noise to the image array and convert it back to an image.

Creating Poisson Noise Pattern

Finally, let's create a Poisson noise pattern on an image. Here's the Python code:

from PIL import Image
import numpy as np

# Open the image
image = Image.open('your_image.jpg')

# Convert the image to a NumPy array
image_array = np.array(image)

# Generate Poisson noise
noisy_image_array = np.random.poisson(image_array).astype(np.uint8)

# Convert the NumPy array back to an image
noisy_image = Image.fromarray(noisy_image_array)

# Save the noisy image
noisy_image.save('poisson_noisy_image.jpg')

In this code, we generate Poisson noise using np.random.poisson() and add it to the image array. Finally, we convert the NumPy array back to an image.

Tips and Tricks

  • Adjusting the Noise Level: You can adjust the noise level by changing the standard deviation for Gaussian noise, the probability for salt and pepper noise, or the intensity for Poisson noise.
  • Applying Noise to Specific Channels: You can apply noise to specific color channels (e.g., red, green, or blue) by manipulating the NumPy array accordingly.
  • Combining Different Types of Noise: You can combine different types of noise to create more complex noise patterns.

Conclusion

Creating noise patterns on an image using Pillow is a straightforward process that can add a unique and artistic touch to your images. Whether you're a photographer looking to simulate film grain or a graphic designer creating a vintage look, Pillow provides the tools you need.

If you're interested in purchasing Pillow products or have any questions about our offerings, including Fisheye Terminals and Busbar U V W, please feel free to contact us for a procurement discussion. We're here to help you find the best solutions for your needs.

References

  • Pillow Documentation: https://pillow.readthedocs.io/en/stable/
  • NumPy Documentation: https://numpy.org/doc/stable/
Send Inquiry