forked from sethoscope/heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
two_pass_example.py
executable file
·77 lines (66 loc) · 2.54 KB
/
two_pass_example.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
#!/usr/bin/env python3
#
# Generates two heat maps from the same data and composites them together.
#
# Copyright 2022 Seth Golub http://www.sethoscope.net/heatmap/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General
# Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
import logging
import sys
import heatmap as hm
import PIL
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
# This is just an example of doing two heatmaps and compositing the
# results, all in one python process. Some of the config is here in
# code, and some needs to be passed on the command line, which is not
# ideal. It could all be moved to new command line arguments with
# defaults, or could all get put into code.
#
# If run with these arguments:
#
# -W 1200 -o out.png -P equirectangular test-data/graffiti.coords
#
# it produces output similar to the graffiti example on the website.
def main():
logging.basicConfig(format='%(relativeCreated)8d ms // %(message)s')
config = hm.Configuration(use_defaults=False)
parser = config.argparser
parser.description = 'make a 2-pass composite heatmap'
args = parser.parse_args()
if args.verbose:
logging.getLogger().setLevel(logging.INFO)
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
config.set_from_options(args)
config.fill_missing()
logging.debug('python version %s' % str(sys.version))
config.decay = 0.3
config.kernel = hm.LinearKernel(5)
config.background = None
matrix = hm.process_shapes(config)
matrix = matrix.finalized()
image1 = hm.ImageMaker(config).make_image(matrix)
config.decay = 0.95
config.kernel = hm.LinearKernel(30)
config.background = 'black'
matrix = hm.process_shapes(config)
matrix = matrix.finalized()
image2 = hm.ImageMaker(config).make_image(matrix)
image2.putalpha(255)
logging.debug(f'image2.mode: {image2.mode}')
image = PIL.Image.alpha_composite(image2, image1)
image.save(args.output)
if __name__ == '__main__':
main()