radxtools / topology-radiomics

Python implementation of topology descriptors which capture subtle sharpness and curvature differences along the surface of diseased pathologies on imaging.
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Imaging Format Compatibility #16

Open tgd15 opened 3 years ago

tgd15 commented 3 years ago

Currently, the Topology Radiomics packages only supports nifty (.nii) images via nibabel.

Sometimes, the labs use the .mha or .mhd imaging formats. Could you please add SimpleITK and/or NumPy support in the compute_morphology_features function to expand imaging format compatibility?

SimpleITK example:

volume = sitk.ReadImage("/path/to/volume.mha") # vol type is SimpleITK.SimpleITK.Image
features = rad.compute_morphology_features(volume, config)

NumPy Array from SimpleITK example:

volume = sitk.ReadImage("/path/to/volume.mha")
volume_np = sitk.GetArrayFromImage(volume) # vol_np type is numpy.ndarray
features = rad.compute_morphology_features(volume_np, config)

To pass a NumPy array from SimpleITK into the compute_morphology_features function, I made the following change:

def compute_morphology_features(mri_mask_voxels: BinaryVoxelMask,
                                config: MorphologyConfig = MorphologyConfig()) -> MorphologyFeatures:
    #mask = mri_mask_voxels.mri_voxel_mask # commented this line out because NumPy array does not have this object
    mask = mri_mask_voxels
satishev commented 3 years ago

Tagging @neshdev and @robtoth to incorporate.

neshdev commented 3 years ago

@tgd15 - I just looked over the code and realized that we wanted to make the package bare bones. We planned to only support numpy arrays. Loading of other MRI images would be done by some external functions and packages written by the user of the package. For example, the code you have above can convert to numpy arrays from SimpleITK formats.

However, looking at the code above, it looks like you are using the function incorrectly

It could be something like this:

import topology_radiomics as rad
sitk_volume = sitk.ReadImage("/path/to/volume.mha")
volume = sitk.GetArrayFromImage(volume)
sanitized_voxels = rad.convert_volume_into_mask(
volume, merge_labels=[])
features_data = rad.compute_morphology_features(sanitized_voxels)

or something like this:

import topology_radiomics as rad
sitk_volume = sitk.ReadImage("/path/to/volume.mha")
volume = sitk.GetArrayFromImage(volume)
sanitized_voxels = rad.BinaryVoxelMask(volume)
features_data = rad.compute_morphology_features(sanitized_voxels)

We have some references for loading data and using other packages in the tutorial notebooks: NiBabel: https://github.com/radxtools/topology-radiomics/blob/master/notebooks/Tutorial%20-%20Getting%20started%20with%20topoplogy_radiomics.ipynb

MedPy: https://github.com/radxtools/topology-radiomics/blob/master/notebooks/Tutorial%20-%20Working%20with%20medpy%20and%20topology_radiomics.ipynb

If you want, we can add another notebook for SimpleITK.

viveksthanam commented 11 months ago

Hello, i am trying to use this for extracting topology features from a CT scan. but i am getting an error "AttributeError: 'numpy.ndarray' object has no attribute 'mri_voxel_mask'" when i pass numpy array, so i wanted to ask if this is only for MRI scans or can i use this for CT Scans too.