Skip to content

Instantly share code, notes, and snippets.

@hasithsura
Last active February 5, 2021 19:50
Show Gist options
  • Save hasithsura/b798c972448bed0b4fa0ab891f244d19 to your computer and use it in GitHub Desktop.
Save hasithsura/b798c972448bed0b4fa0ab891f244d19 to your computer and use it in GitHub Desktop.
def spec_to_image(spec, eps=1e-6):
mean = spec.mean()
std = spec.std()
spec_norm = (spec - mean) / (std + eps)
spec_min, spec_max = spec_norm.min(), spec_norm.max()
spec_scaled = 255 * (spec_norm - spec_min) / (spec_max - spec_min)
spec_scaled = spec_scaled.astype(np.uint8)
return spec_scaled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment