Original C-contiguous: True
Transposed C-contiguous: False
original contiguous: 21.26 ms
transposed view: 15.80 ms
Slowdown: -25.7%
ascontiguousarray copy: 527.5 ms, extra memory: 244.1 MB
Deep learning frameworks, CUDA/OpenCL, ONNX, and many imaging libraries require contiguous buffers—making the copy unavoidable.
5. DiCube’s Approach: Unified Axis Order
dicube.load_from_dicom_folder() resolves axis order once during load:
Read data/metadata.
Interpret memory as (Z, Y, X) in C‑contiguous fashion without copying.
Flip space metadata so spacing/origin/orientation also follow (Z, Y, X).
Result: arrays and metadata align; downstream code can treat everything as (Z, Y, X).
import dicubedcb_image = dicube.load_from_dicom_folder(dirname, sort_method=dicube.SortMethod.POSITION_RIGHT_HAND)print("--- DiCube (consistent) ---")print("array.shape ->", dcb_image.get_fdata().shape, "(Z, Y, X)")print("space.spacing ->", dcb_image.space.spacing, "(Z, Y, X)")print("\n--- SimpleITK (mixed) ---")print("array.shape ->", array.shape, "(Z, Y, X)")print("image.GetSpacing() ->", sitk_image.GetSpacing(), "(X, Y, Z)")
--- DiCube (consistent) ---
array.shape -> (200, 512, 512) (Z, Y, X)
space.spacing -> (0.4499999999999998, 0.4296875, 0.4296875) (Z, Y, X)
--- SimpleITK (mixed) ---
array.shape -> (200, 512, 512) (Z, Y, X)
image.GetSpacing() -> (0.4296875, 0.4296875, 0.4499999999999998) (X, Y, Z)
DiCube avoids extra rearrangements while exposing an intuitive API, eliminating axis confusion and fragile conversions.