Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update resize.py #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 52 additions & 48 deletions data/resize.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,70 @@
import os
import constants
import numpy as np
from scipy import misc, ndimage
from matplotlib.pyplot import imread, imsave
import cv2


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


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)
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 = 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)
imsave(os.path.join(destPath, file), picResized)


def main():
prepath = os.path.join(os.getcwd(), 'dataset-original')
glassDir = os.path.join(prepath, 'glass')
paperDir = os.path.join(prepath, 'paper')
cardboardDir = os.path.join(prepath, 'cardboard')
plasticDir = os.path.join(prepath, 'plastic')
metalDir = os.path.join(prepath, 'metal')
trashDir = os.path.join(prepath, 'trash')
prepath = os.path.join(os.getcwd(), 'dataset-original')
glassDir = os.path.join(prepath, 'glass')
paperDir = os.path.join(prepath, 'paper')
cardboardDir = os.path.join(prepath, 'cardboard')
plasticDir = os.path.join(prepath, 'plastic')
metalDir = os.path.join(prepath, 'metal')
trashDir = os.path.join(prepath, 'trash')

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

destPath = os.path.join(os.getcwd(), 'dataset-resized')
try:
os.makedirs(destPath)
except OSError:
if not os.path.isdir(destPath):
raise
# GLASS
fileWalk(glassDir, os.path.join(destPath, 'glass'))

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

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

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

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

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

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

if __name__ == '__main__':
main()
main()