Reputation: 2244
I want to identify if the image contains noise. Example: Salt and Pepper Noise or Gaussian Noise. I also want to measure the amount of noise present in the image. How shall I do it? Can I do it by analyzing the histogram of the images? Below is my initial code;
import matplotlib.pyplot as plt
import numpy as np
import os.path
if __name__ == '__main__':
image_counter = 1
while True:
if not os.path.isfile('crop_images/' + str (image_counter) + '.png'):
break
image_path = 'crop_images/' + str(image_counter) + '.png'
image = plt.imread(image_path)
#Display Histogram
print(image)
print(image.ravel())
n, bins, patches = plt.hist(image.ravel(), bins = 256)
plt.title('Image Patch # ' + str(image_counter))
plt.xlabel('Grey Value')
plt.ylabel('Frequency')
window = plt.get_current_fig_manager()
window.canvas.set_window_title('Histogram')
plt.show()
image_counter = image_counter + 1
Upvotes: 0
Views: 1093
Reputation: 2741
S&P noise: It means some random pixels of your image are set to black or white (or some constant value per channel). If you have spikes at 0 and 255 values (or some constant value per channel) in the histogram of the image, you likely have salt and pepper noise. You can apply a median filter to get rid of the noise, and the size of your kernel that minimizes the spikes in the histogram can inform you about the noise level.
Gaussian noise: It means there is some blur in the image. Laplacian kernels are best both to generate and detect blur. If you apply a Laplacian kernel to your image and take its variance, the answer will give you how "edgy" the image is. If the number is high, it means the variance is high, it means there are sudden changes (i.e. edges!) in the image, which means less blur.
Upvotes: 2