Question: I'm new in programming and I'd like to ask you how can I write my code so that it read all the pic whitin a directory, process it one by one, and then save the output images in another directory.

```
%pylab
%matplotlib inline
import cv2
import glob
import os
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

filename = [img for img in glob.glob("outp/*.png")]
flist=sorted(filename)

images = []
for img in flist:
    n = cv2.imread(img, 0)
    images.append(n)
    blur = cv.GaussianBlur(n, (9,9), 0)
    cv.imwrite(flist, blur) #definitly wrong!! but idk how to do it

```

Answer: 
You don't need to create a list of all the pixel data of all the images in memory, that is just wasteful of memory. So, remove the lines:

```
images = []

```

and

```
images.apoend(...)

```

Then change your `imwrite()` to overwrite the current image:

```
cv2.imwrite(img,blur)

```

---

Here's a more complete version:

```
#!/usr/bin/env python3

import cv2
import glob
import os
import numpy as np
import cv2

# Go to where the images are
os.chdir('outp')

# Get list of filenames to convert
files = glob.glob("*.png")

for file in files:
    n = cv2.imread(file, 0)
    blur = cv2.GaussianBlur(n, (9,9), 0)
    cv2.imwrite('blurred_' + file, blur) 

```
Try this way:
`cv2.imwrite("mypicture.jpg", gray[y:y+h,x:x+w])`