MCPcopy Create free account
hub / github.com/LeapLabTHU/ActiveNeRF / _minify

Function _minify

load_llff.py:8–57  ·  view source on GitHub ↗
(basedir, factors=[], resolutions=[])

Source from the content-addressed store, hash-verified

6########## see https://github.com/Fyusion/LLFF for original
7
8def _minify(basedir, factors=[], resolutions=[]):
9 needtoload = False
10 for r in factors:
11 imgdir = os.path.join(basedir, 'images_{}'.format(r))
12 if not os.path.exists(imgdir):
13 needtoload = True
14 for r in resolutions:
15 imgdir = os.path.join(basedir, 'images_{}x{}'.format(r[1], r[0]))
16 if not os.path.exists(imgdir):
17 needtoload = True
18 if not needtoload:
19 return
20
21 from shutil import copy
22 from subprocess import check_output
23
24 imgdir = os.path.join(basedir, 'images')
25 imgs = [os.path.join(imgdir, f) for f in sorted(os.listdir(imgdir))]
26 imgs = [f for f in imgs if any([f.endswith(ex) for ex in ['JPG', 'jpg', 'png', 'jpeg', 'PNG']])]
27 imgdir_orig = imgdir
28
29 wd = os.getcwd()
30
31 for r in factors + resolutions:
32 if isinstance(r, int):
33 name = 'images_{}'.format(r)
34 resizearg = '{}%'.format(100./r)
35 else:
36 name = 'images_{}x{}'.format(r[1], r[0])
37 resizearg = '{}x{}'.format(r[1], r[0])
38 imgdir = os.path.join(basedir, name)
39 if os.path.exists(imgdir):
40 continue
41
42 print('Minifying', r, basedir)
43
44 os.makedirs(imgdir)
45 check_output('cp {}/* {}'.format(imgdir_orig, imgdir), shell=True)
46
47 ext = imgs[0].split('.')[-1]
48 args = ' '.join(['mogrify', '-resize', resizearg, '-format', 'png', '*.{}'.format(ext)])
49 print(args)
50 os.chdir(imgdir)
51 check_output(args, shell=True)
52 os.chdir(wd)
53
54 if ext != 'png':
55 check_output('rm {}/*.{}'.format(imgdir, ext), shell=True)
56 print('Removed duplicates')
57 print('Done')
58
59
60

Callers 1

_load_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected