-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresizeimages.py
111 lines (69 loc) · 3.04 KB
/
resizeimages.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 15:25:23 2019
@author: nithish k
"""
import glob
import os
import imageManipulations
import plotGridAndBound
import XMLParser
import assigngrid
import normalization
import denormalization
import generateTargetVariable
import decodePredictionArray
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import pickle
import nonMaxSupression
from image_operations import get_image_after_rotation
classMappingDict = {'milk':0,'tomato': 1, 'apple':2 , 'eggs':3 ,'onion': 4,
'salt':5, 'yogurt': 6, 'sugar': 7, 'butter': 8, 'orange':9}
##change for size
dictOfTranslations = {'resizeWidth' : 342, 'resizeHeight' : 342}
rWidth,rHeight = dictOfTranslations['resizeWidth'],dictOfTranslations['resizeHeight']
GRID_SIZE = 19
### change dirs
inpImagesfileDir = "./renamed_images/augmented data/images/"
inpAnnotations = "./renamed_images/augmented data/annotations/"
outputdirImages = "./renamed_images/resized/images/"
outputAnnotations = "./renamed_images/resized/annotations/"
with open(inpAnnotations+'/ImageDictsAllFiles.pkl', 'rb') as f:
AllImageDictList = pickle.load(f)
with open(inpAnnotations+'/ObjectListsAllFiles.pkl', 'rb') as f:
AllObjectsList = pickle.load(f)
with open(inpAnnotations+'/AllTargetArray.pkl', 'rb') as f:
AllImgTargetArray = pickle.load(f)
with open(inpAnnotations+'/AllFileNames.pkl', 'rb') as f:
imgfileNamesList = pickle.load(f)
newAllImageDictList,newAllObjectsList = [],[]
newAllImageAsNPArray = []
newAllImgTargetArray = []
newImgfileNamesList = []
for index,inpBasefileName in enumerate(imgfileNamesList):
inpImageFile= inpImagesfileDir+inpBasefileName
outputImagepath = outputdirImages+inpBasefileName
imageManipulations.imageResize(inpImageFile,outputImagepath,rWidth,rHeight) ##saves new image
new_img_array = plt.imread(outputImagepath)
origImgDict = AllImageDictList[index]
origObjList = AllObjectsList[index]
newImageDict,newObjectList = imageManipulations.ResizeDict(origImgDict,origObjList,dictOfTranslations)
newEachImgTarget = generateTargetVariable.genTargetArray('',newImageDict,newObjectList,
GRID_SIZE,GRID_SIZE,classMappingDict )
newAllImageAsNPArray.append(new_img_array)
newAllImageDictList.append(newImageDict)
newAllObjectsList.append(newObjectList)
newAllImgTargetArray.append(newEachImgTarget)
newImgfileNamesList.append(inpBasefileName)
with open(outputAnnotations+'/ImageDictsAllFiles.pkl', 'wb') as f:
pickle.dump(newAllImageDictList, f)
with open(outputAnnotations+'/ObjectListsAllFiles.pkl', 'wb') as f:
pickle.dump(newAllObjectsList, f)
with open(outputAnnotations+'/AllImgNPArray.pkl', 'wb') as f:
pickle.dump(newAllImageAsNPArray, f)
with open(outputAnnotations+'/AllTargetArray.pkl', 'wb') as f:
pickle.dump(newAllImgTargetArray, f)
with open(outputAnnotations+'/AllFileNames.pkl', 'wb') as f:
pickle.dump(newImgfileNamesList, f)