Add Noise to Image in Matlab
Add Noise to Image in Matlab

If youโ€™ve ever wondered how to add noise to image in MATLAB, youโ€™re in the right place! Noise addition is a crucial step in testing image processing algorithms, understanding how they handle real world imperfections, or simply experimenting with different filtering techniques. This blog will guide you through the process of how to add noise to image in MATLAB step by step, including the most commonly used noise types: Gaussian Noise, Salt & Pepper Noise, and Speckle Noise.

By the end of this article, you’ll not only understand the types of noise you can add but also learn how to implement a MATLAB script that applies all these noise types to any image. ๐Ÿš€


What is Noise in Images?

Before we jump into MATLAB, letโ€™s quickly understand what image noise is. Noise refers to unwanted random variations in pixel values, often caused by factors like:

  • Sensor imperfections ๐Ÿ“ท
  • Environmental interference ๐ŸŒฉ๏ธ
  • Transmission errors ๐Ÿ“ก

In the context of image processing, noise can degrade the quality of an image, making it look grainy, blurry, or distorted. One way is using different filters you can find application of MMSE & Adaptive Median Filter here


Types of Noise You Can Add in MATLAB

MATLAB provides a straightforward way to add noise using the imnoise function. Here are the most commonly used types:

1. Gaussian Noise ๐ŸŒŸ

Gaussian noise, also known as normal noise, follows a bell-shaped distribution. Each pixel value is randomly altered according to this distribution.


The formula for adding Gaussian noise is:


    \[I_{\text{noisy}} = I + \mathcal{N}(\mu, \sigma^2)\]

Where

  • I = \text{Original image}
  • \mathcal{N}(\mu, \sigma^2) \text{ Gaussian Noise with mean } \mu \text{ and variance } \sigma^2

Use Case: Testing smoothing filters like the Gaussian filter.


2. Salt & Pepper Noise ๐Ÿง‚๐ŸŒถ๏ธ

Salt & pepper noise randomly sets some pixels to black (pepper) and others to white (salt). This creates a “sprinkled” effect on the image.

Use Case: Evaluating the performance of median filters and noise removal techniques.


3. Speckle Noise โœจ

Speckle noise multiplies pixel values by a random noise factor, simulating interference commonly seen in medical and radar imaging.

Use Case: Testing despeckling algorithms, especially for SAR (Synthetic Aperture Radar) images.


4. Poisson Noise

Poisson noise arises from photon-counting mechanisms in devices like cameras, making it common in low-light conditions.

Use Case: Simulating low-light scenarios for testing algorithms.


How to Add Noise to Images in MATLAB

Letโ€™s now dive into MATLAB and explore how to add these types of noise to an image.


Step-by-Step Tutorial: Add Noise to Image in MATLAB

Hereโ€™s a detailed guide on how to add noise to image in MATLAB. So here we are taking our site logo as the base example thus all the example images would be of the Logo of the site Hishuanigami โค๏ธโค๏ธโค๏ธ

Step 1: Import an Image

First, letโ€™s load an image into MATLAB. If the image is in color, weโ€™ll convert it to grayscale for simplicity.

original to greyscale image

Step 2: Add Different Types of Noise

Now weโ€™ll use MATLABโ€™s imnoise function to add Gaussian noise, salt & pepper noise, and speckle noise to the image.


Step 3: Display and Save the Noisy Images

Weโ€™ll display the original and noisy images side-by-side for easy comparison. Each noisy image will also be saved to your working directory.

added noise to the original image
result of adding different noises to Original image

So, in the above image we can see the noise, but it is not very prominent so what i did was just adjusted the parameters in Step 2 and tuned them up a bit here are the updated parameters

% Step 2: Add Noise 
gaussian_noisy = imnoise(input_image, 'gaussian', 0, 0.07);
saltpepper_noisy = imnoise(input_image, 'salt & pepper', 0.09);
speckle_noisy = imnoise(input_image, 'speckle', 0.05);

And the Result of this is actually a noise that can be seen and not just sprinkle here and there, you can adjust these parameters in whatever way you want.

Add Noise to Image in Matlab
Added More Noise to the Original Image

Complete Script

Hereโ€™s the full script for convenience:

Why Add Noise to an Image in MATLAB?

The are of addition of noise is not just for fun it serves critical purposes in image processing:

  • Testing Filters: Check the effectiveness of noise reduction techniques.
  • Simulating Real-World Scenarios: Prepare algorithms to handle imperfect inputs.
  • Enhancing Robustness: Make systems resilient to environmental challenges.

Final Thoughts

Learning how to add noise to image in MATLAB is a powerful skill that bridges the gap between theoretical concepts and practical applications. Whether you’re a beginner learning about noise or an advanced researcher, this tutorial gives you the tools to experiment and test effectively. ๐Ÿ› ๏ธ

Try out the script and unleash your creativity with noisy images! If you have any questions or cool ideas to share, drop them in the comments below. Happy Coding & MATLAB-ing! ๐Ÿš€๐Ÿš€๐Ÿš€

Thank for reading our guide on how to add noise to image in MATLAB

If you want to Learn how to apply Gaussian Filter to any image to reduce the Gaussian Noise, you can find that out here and if you want to learn how to Implement MMSE filter or Adaptive Median Filter you can find that out here

Leave a Reply

Your email address will not be published. Required fields are marked *