-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_viewer.py
125 lines (115 loc) · 4.72 KB
/
update_viewer.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
import os
import glob
from natsort import natsorted
import shutil
from distutils.dir_util import copy_tree
import cv2 as cv
import numpy as np
GV_BASE_URL = 'https://gigazoom.rc.duke.edu/'
def get_path_from_url(url):
return os.path.join('/home/rapiduser/', url[len(GV_BASE_URL):])
def make_url(path):
return os.path.join(GV_BASE_URL, path)
def make_composite(image_paths):
images = [cv.imread(image_path) for image_path in image_paths]
composite = np.zeros((300,300,3), dtype=np.uint8)
if len(images) == 0:
raise RuntimeError()
elif len(images) == 1:
composite = cv.resize(images[0], (300, 300))
elif len(images) == 2:
composite = cv.resize(images[0], (300, 300))
composite[:, 150:] = cv.resize(images[1], (300, 300))[:, 150:]
elif len(images) == 3:
composite[:150, :150] = cv.resize(images[0], (150, 150))
composite[:, 150:] = cv.resize(images[1], (300, 300))[:, 150:]
composite[150:, :150] = cv.resize(images[2], (150, 150))
else:
composite[:150, :150] = cv.resize(images[0], (150, 150))
composite[:150, 150:] = cv.resize(images[1], (150, 150))
composite[150:, :150] = cv.resize(images[2], (150, 150))
composite[150:, 150:] = cv.resize(images[3], (150, 150))
return composite
def generate_group(base_dir):
with open(os.path.join(base_dir, 'order.json')) as fp:
order_data = json.load(fp)['order']
dzi_files = [os.path.join(base_dir, of) for of in order_data]
meta_path = os.path.join(base_dir, 'metadata.json')
if os.path.exists(meta_path):
with open(meta_path) as fp:
meta = json.load(fp)
else:
meta = {}
if 'height' in meta:
height = meta['height']
else:
height = 0.07424
gid = os.path.basename(base_dir)
if gid == '':
gid = os.path.basename(os.path.dirname(base_dir))
# HARDCODING FOR NOW
title = gid
source_type = 'Visible'
idx = 0
thumbnail_folder = os.path.splitext(dzi_files[0])[0] + "_files"
pyramid_folders = natsorted(glob.glob(os.path.join(thumbnail_folder, '*/')))[::-1]
# now iterate backwards until there is only a single file in the folder
for pf in pyramid_folders:
images = glob.glob(os.path.join(pf, '*.*'))
if len(images) == 1:
break
thumbnail_image = images[0]
group_data = {
'gid': gid,
'title': title,
'thumbnailImg': make_url(thumbnail_image),
'idx': idx,
'kind': 'capture',
'height': height,
'sources': [
{
'type': source_type,
'tileSources': [make_url(dzi_file) for dzi_file in dzi_files]
}
]
}
return group_data
if __name__ == "__main__":
manifest_data = {}
# first get the team folders
teams = glob.glob(os.path.join('auto', '*/')
print("teams: ", teams)
manifest_data = {"groups": {}}
for team in teams:
team_data = {'groups': {}, 'kind': 'team'}
team_data['title'] = os.path.basename(team[:-1])
# then get the projects
projects = glob.glob(os.path.join(team, '*/')
print("projects: ", projects)
for project in projects:
project_data = {'groups': {}}
project_name = os.path.basename(project[:-1])
project_data['title'] = project_name
captures = glob.glob(os.path.join(project, '*/')
print("captures: ", captures)
for capture in captures:
capture_data = generate_group(capture)
capture_name = capture_data['title']
project_data['groups'][capture_name] = capture_data
groups = project_data['groups']
# make the composite image for the project
target_image_paths = [get_path_from_url(group['thumbnailImg']) for group in groups.values()]
composite_image = make_composite(target_image_paths)
thumb_img_path = os.path.join(project, f'{project_name}-thumbnail.jpg').replace(' ', '-')
cv.imwrite(thumb_img_path, composite_image)
project_data['thumbnailImg'] = make_url(thumb_img_path)
team_data['groups'][project_name] = project_data
# lazily grabbing the last thumbnail image
team_data['thumbnailImg'] = thumb_img_path
manifest_data['groups'][team_data['title']] = team_data
with open('image_manifest.json', 'w') as fp:
json.dump(manifest_data, fp)
shutil.copy2('image_manifest.json', '/home/rapiduser/gigaviewer/gigaviewer-ui/src/components/image-viewer/imageMetadata.json')
os.system('yarn --cwd /home/rapiduser/gigaviewer/gigaviewer-ui/ build')
copy_tree('/home/rapiduser/gigaviewer/gigaviewer-ui/build/', '/var/www/html/')