Skip to content

Commit

Permalink
Added convenience script show_cmaps.py
Browse files Browse the repository at this point in the history
- visualize multiple color maps at once, and all built-in ones by
  default
  • Loading branch information
chr5tphr committed Oct 14, 2021
1 parent 6435080 commit 63779db
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions share/scripts/show_cmaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''Script to visually inspect color maps.'''
import click
import numpy as np
from PIL import Image

from zennit.image import CMAPS, palette


def semsstr(string):
if isinstance(string, list):
return string
return [obj for obj in string.split(';') if obj]


@click.command()
@click.argument('output')
@click.option('--cmap', 'colormap_src', type=semsstr, default=list(CMAPS))
@click.option('--level', type=float, default=1.0)
def main(output, colormap_src, level):
print('\n'.join(colormap_src))
palettes = np.stack([palette(obj, level) for obj in colormap_src])
arr = np.repeat(palettes, 32, 0)
img = Image.fromarray(arr)
img.save(output)


if __name__ == '__main__':
main()

0 comments on commit 63779db

Please sign in to comment.