-
-
Save wyli/50c65e686beaf418a32c9cc131f0bdc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
import numpy as np | |
with h5py.File("post_label0002.h5", "r") as hf: | |
data = hf['post_label'][()] | |
print(data.shape) | |
# (1, 118, 247, 247, 277) | |
from monai.transforms.utils import map_classes_to_indices, generate_label_classes_crop_centers | |
indices = map_classes_to_indices(data[0], max_samples_per_class=10000) | |
h, w, z = 247, 247, 277 | |
coords = generate_label_classes_crop_centers([h, w, 1], num_samples=10, label_spatial_shape=[h, w, z], indices=indices) | |
z_slice = [c[-1] for c in coords] | |
# 10 samples coordinates | |
# coords: ((123, 123, 170), (123, 123, 4), (123, 123, 270), (123, 123, 157), (123, 123, 73), (123, 123, 254), (123, 123, 30), (123, 123, 185), (123, 123, 229), (123, 123, 255)) | |
# z_slice: [170, 4, 270, 157, 73, 254, 30, 185, 229, 255] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment