File size: 2,348 Bytes
1ff05ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82dd7fd
1ff05ed
 
82dd7fd
1ff05ed
 
 
 
 
82dd7fd
1ff05ed
7d57842
1ff05ed
 
 
 
 
 
 
 
bf68858
1ff05ed
 
bf68858
1ff05ed
 
82dd7fd
1ff05ed
 
bf68858
1ff05ed
 
bf68858
1ff05ed
 
82dd7fd
1ff05ed
 
bf68858
1ff05ed
 
 
 
 
f0aa344
1ff05ed
 
bf68858
1ff05ed
 
bf68858
1ff05ed
 
82dd7fd
1ff05ed
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import constants
import numpy as np
from scipy import misc, ndimage

def resize(image, dim1, dim2):
	return misc.imresize(image, (dim1, dim2))

def fileWalk(directory, destPath):
	try: 
		os.makedirs(destPath)
	except OSError:
		if not os.path.isdir(destPath):
			raise

	for subdir, dirs, files in os.walk(directory):
		for file in files:
			if len(file) <= 4 or file[-4:] != '.jpg':
				continue

			pic = misc.imread(os.path.join(subdir, file))
			dim1 = len(pic)
			dim2 = len(pic[0])
			if dim1 > dim2:
				pic = np.rot90(pic)

			picResized = resize(pic,constants.DIM1, constants.DIM2)
			misc.imsave(os.path.join(destPath, file), picResized)
		

def main():
	prepath = os.path.join(os.getcwd(), 'Combined')
	batteryDir = os.path.join(prepath, 'battery')
    biologicalDir = os.path.join(prepath, 'biological')
    brownglassDir = os.path.join(prepath, 'brown-glass')
    cardboardDir = os.path.join(prepath, 'cardboard')
    clothesDir = os.path.join(prepath, 'clothes')
    greenglassDir = os.path.join(prepath, 'green-glass')
	metalDir = os.path.join(prepath, 'metal')
	paperDir = os.path.join(prepath, 'paper')
	plasticDir = os.path.join(prepath, 'plastic')
	shoesDir = os.path.join(prepath, 'shoes')
	trashDir = os.path.join(prepath, 'trash')
	whiteglassDir = os.path.join(prepath, 'white-glass')

	destPath = os.path.join(os.getcwd(), 'Combined-resized')
	try: 
		os.makedirs(destPath)
	except OSError:
		if not os.path.isdir(destPath):
			raise


	#BATTERY
	fileWalk(batteryDir, os.path.join(destPath, 'battery'))

	#BIOLOGICAL
	fileWalk(biologicalDir , os.path.join(destPath, 'biological'))

	#BROWN-GLASS
	fileWalk(brownglassDir, os.path.join(destPath, 'brown-glass'))

	#CARDBOARD
	fileWalk(cardboardDir, os.path.join(destPath, 'cardboard'))

	#CLOTHES
	fileWalk(clothesDir, os.path.join(destPath, 'clothes'))

	#GREEN-GLASS
	fileWalk(greenglassDir, os.path.join(destPath, 'green-glass'))

	#METAL
	fileWalk(metalDir, os.path.join(destPath, 'metal'))

	#PAPER
	fileWalk(paperDir, os.path.join(destPath, 'paper'))

	#PLASTIC
	fileWalk(plasticDir, os.path.join(destPath, 'plastic'))

	#SHOES
	fileWalk(shoesDir, os.path.join(destPath, 'shoes'))

	#TRASH
	fileWalk(trashDir, os.path.join(destPath, 'trash'))

	#WHITE-GLASS
	fileWalk(whiteglassDir, os.path.join(destPath, 'white-glass'))

if __name__ == '__main__':
    main()