Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active February 18, 2021 02:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
HDF5 image stack writing, suitable for HDFView video player
Simg = load('clown');
imgs = Simg.X;
file = 'img.h5';
name = '/img';
h5create(file, name, size(imgs))
h5write(file, name, imgs)
h5writeatt(file, name, 'CLASS', 'IMAGE')
h5writeatt(file, name, 'IMAGE_VERSION', '1.2')
h5writeatt(file, name, 'IMAGE_SUBCLASS', 'IMAGE_GRAYSCALE')
h5writeatt(file, name, "DISPLAY_ORIGIN", "LL")
h5writeatt(file, name, "IMAGE_WHITE_IS_ZERO", uint8(0))
import numpy as np
import h5py
# images is a numpy ndarray N x X x Y images
with h5py.File("image.h5", "w") as f:
h = f.create_dataset("/images", data=images)
h.attrs["CLASS"] = np.string_("IMAGE")
h.attrs["IMAGE_VERSION"] = np.string_("1.2")
h.attrs["IMAGE_SUBCLASS"] = np.string_("IMAGE_GRAYSCALE")
h.attrs["DISPLAY_ORIGIN"] = np.string_("LL")
h.attrs["IMAGE_WHITE_IS_ZERO"] = np.uint8(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment