-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_images.py
More file actions
40 lines (39 loc) · 1.69 KB
/
Copy pathcreate_images.py
File metadata and controls
40 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
###
### This program actually flips all of the images around and leaves the intended negative images the same.
### It will create a new file for the results.
###
from PIL import Image
import os
import numpy.random as r
os.mkdir("test/training2")
for dir in os.listdir("test/training"):
if dir != '.DS_Store':
os.mkdir("test/training2/" + dir)
for file in os.listdir("test/training/" + dir):
picture = Image.open("test/training/" + dir + "/" + file)
newimage = Image.new('L', picture.size)
pix1 = picture.load()
pix2 = newimage.load()
k = r.randint(20) # If your desired percentage is not a multiple of 5%, modify this number.
for i in range(0, picture.width):
for j in range(0, picture.height):
if k % 20 <= 1: # Modify this value to control the number of negative images.
pix2[i, j] = pix1[i, j]
else:
pix2[i, j] = 255 - pix1[i, j]
newimage.save("test/training2/" + dir + "/" + file)
picture.close()
newimage.close()
os.mkdir("test/testing2")
for dir in os.listdir("test/testing"):
if dir != '.DS_Store':
os.mkdir("test/testing2/" + dir)
for file in os.listdir("test/testing/" + dir):
picture = Image.open("test/testing/" + dir + "/" + file)
newimage = Image.new('L', picture.size)
pix1 = picture.load()
pix2 = newimage.load()
for i in range(0, picture.width):
for j in range(0, picture.height):
pix2[i, j] = pix1[i, j]
newimage.save("test/testing2/" + dir + "/" + file)