Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active February 18, 2021 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/bdae2d21d9a8d6cb42913d07d579827e to your computer and use it in GitHub Desktop.
Save scivision/bdae2d21d9a8d6cb42913d07d579827e to your computer and use it in GitHub Desktop.
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