-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJoint.py
More file actions
64 lines (42 loc) · 1.67 KB
/
Joint.py
File metadata and controls
64 lines (42 loc) · 1.67 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
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
import cv2
import glob
import numpy as np
class Joint:
def __init__(self, input_path, output_path):
imgFiles = glob.glob(input_path)
dicImage = {}
row, col = 0, 0
for imgFile in imgFiles:
fileName = imgFile.replace('.jpg', '')
x, y = self.getPos(fileName[fileName.rfind('\\') + 1:])
row, col = max(row, y), max(col, x)
img = cv2.imread(imgFile)
dicImage[(x, y)] = img
self.Merge(dicImage, row, col, output_path)
def getPos(self, fileName):
x, y = fileName.split('x')
return map(int, (x, y))
def Merge(self, dicImage, row, col, output_path):
resImg = None
dicCol = {}
for i in range(col + 1):
tempImg = None
for j in range(row + 1):
if tempImg is not None:
tempImg = np.vstack([tempImg, dicImage[i, j]])
else:
tempImg = dicImage[(i, j)]
dicCol[i] = tempImg
for i in range(len(dicCol)):
if resImg is not None:
resImg = np.hstack([resImg, dicCol[i]])
else:
resImg = dicCol[i]
cv2.imwrite(output_path, resImg)
if __name__ == '__main__':
category = 'SpinalCord'
input_path = 'Specimens/'+ category + '/' + '*.jpg'
output_path = 'JointPhoto/' + category + '.jpg'
joint = Joint(input_path, output_path)
# processImg = cv2.resize(img, (newImgH, newImgW), interpolation = cv2.INTER_AREA)
# cv2.imwrite('SpecimensProcessed/' + fileName, processImg )