0

Is there any technique to add salt and pepper noise to all images in a directory in python.

  • 1
    Possible duplicate of [Adding Gaussian noise to image](https://stackoverflow.com/questions/55261087/adding-gaussian-noise-to-image) – m13op22 Oct 21 '19 at 15:00

1 Answers1

0

While looping through the directory, you need to load each image, add salt and pepper noise and save it back.

  1. Looping through a directory
from PIL import Image
import glob
image_list = []
for filename in glob.glob('yourpath/*.jpg'): #assuming jpg
    img = Image.open(filename)
    # Code to add salt and pepper noise
  1. Adding salt and pepper noise, here is a great post you can look into.

  2. Save the image back inside the loop,

filename = "images/file_%d.jpg"%d
cv2.imwrite(filename, frame)
d+=1

I purposefully didn't provide you the direct code. Please analyze and figure it out. More than achieving your goal of adding salt and pepper noise, it is important to learn as to how to solve the problem and the thought process. Next time, please do your research, analyse and solve your problem. Post your questions here as a last resort after exhausting your search.

Ghost
  • 450
  • 3
  • 14
  • Thank u sir for the instruction but I tried it in this way only previously before posting the question. I m getting an error as numpy.ndarray do not have the attribute to write – Amit Sen Oct 22 '19 at 18:45