-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_non_singleproduct.py
35 lines (29 loc) · 1.07 KB
/
remove_non_singleproduct.py
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
import glob
import os
from PIL import Image
import numpy as np
directory = "/home/scopeserver/RaidDisk/Filter_Full/"
file_paths = [] # List which will store all of the full filepaths.
# Walk the tree.
#textfile = open('single_product.txt','w')
for root, directories, files in os.walk(directory):
for filename in files:
# Join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename)
#file_paths.append(filepath) # Add it to the list.
#textfile.write("%s\n" % filepath)
print(filepath)
img = np.array(Image.open(filepath))
img = np.mean(img,2)
if np.abs(np.max(img[0,:])-np.min(img[0,:]))>30:
os.remove(filepath)
continue
elif np.abs(np.max(img[-1,:])-np.min(img[-1,:]))>30:
os.remove(filepath)
continue
elif np.abs(np.max(img[:,0])-np.min(img[:,0]))>30:
os.remove(filepath)
continue
elif np.abs(np.max(img[:,-1])-np.min(img[:,-1]))>30:
os.remove(filepath)
continue