cabouman / mbircone

BSD 3-Clause "New" or "Revised" License
11 stars 9 forks source link

HDF5 utils #155

Closed dyang37 closed 8 months ago

dyang37 commented 9 months ago

This PR is regarding the utility functions to save image data into an HDF5 file and read image data from an HDF5 file. This PR contains two functions mbircone.utils.hdf5_write() and mbircone.utils.hdf5_read(), as well as a demo script demo/demo_hdf5_io.py.

dyang37 commented 9 months ago

Updated function interfaces (approved by Charlie):

def hdf5_write(image, filename,
              recon_description="", alu_description ="", delta_pixel_image=1.0):
    """ This function writes a reconstructed image to an HDF5 file containing the 3D reconstructed volume along with optional descriptions of the source data, and units. 

    Args:
        image (float, ndarray): 3D reconstructed image to be saved.
        filename (string) Path to save the HDF5 file. Example: "<path_to_directory>/recon.h5".
        recon_description (string, optional) [Default=""] description of CT source data.
        alu_description (string, optional) [Default=""] description of arbitrary length units (ALU). Example: "1 ALU = 5 mm".
        delta_pixel_image (float, optional) [Default=1.0]:  Image pixel spacing in ALU.
    """
def hdf5_read(filename):
    """ Read the image data as well as its metadata from an HDF5 file.

    Args:
        filename (string, optional) [Default="recon.h5"] Path to save the HDF5 file.

    Returns:
        two-element tuple containing:

        - **image** (*ndarray*): 3D image data.
        - **attributes** (*dict*): A dictionary containing attributes of the HDF5 file.
    """
dyang37 commented 9 months ago

File content:

    The resulting HDF5 file contains the following entries:
    Dataset:
        - **voxels** (*ndarray*): 3D image to be saved.
    Attributes:
        - **README** (*string*): describes the contents of HDF5 file.
        - **source_data_description** (*string*): description of CT source data.
        - **alu_description** (*string*): description of arbitrary length units (ALU). Example: "1 ALU = 5 mm".
        - **delta_pixel_image** (*float*): Image pixel spacing in ALU.
        - **recon_scale_description** (*string*): description of the reconstruction scale. Example: "mm^{-1}" or "Hounsfield Units".
dyang37 commented 8 months ago

Close this PR for further modifications.