-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage_Tester.py
More file actions
40 lines (31 loc) · 1.08 KB
/
Image_Tester.py
File metadata and controls
40 lines (31 loc) · 1.08 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
#!/usr/bin/env python
#Importing the required libraries
import os, random, argparse
from PIL import Image
import numpy as np
parser = argparse.ArgumentParser(description='Checks background images for correct number of channels')
parser.add_argument('--images', dest='images', required=True, help="Diectory of images")
args = parser.parse_args()
moveme = []
## This tests to make sure the dimensions of all the photos are the same
for filename in os.listdir(args.images):
path = args.images+filename
try:
x = Image.open(path)
im = np.array(x)
try:
w, h, d = im.shape
ext = filename.split('.')[len(filename.split('.'))-1]
if not(ext == "jpg" or ext == "jpeg" or ext == "png"):
moveme.append(filename)
except:
moveme.append(filename)
except:
continue
if (len(moveme) > 0):
command = "mkdir Unusable_Images"
os.system(command)
for item in moveme:
q = '"' + args.images+item + '"'
command = "mv " + q + " Unusable_Images/"
os.system(command)