Skip to content

Commit

Permalink
STYL: Add FAQ for image and mask of different geometry
Browse files Browse the repository at this point in the history
Add FAQ explaining PyRadiomics behavior when using image and mask with different geometry.

Additionally, add an example script, usable from the commandline, that resamples a mask to a reference image. This allows users to force a mask to the same geometry as the image, so it can be used in PyRadiomics without resampling.
  • Loading branch information
JoostJM committed Mar 24, 2017
1 parent 5551316 commit 04c4a9e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bin/resampleMask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
This script is an example of how a mask image can be resampled to the geometry of a reference image. This enables the
a mask that has been generated on one image, to be used for feature extraction of another image. Please note that this
still requires the mask to have a similar physical space as the reference image.
This script can be used directly from the command line by calling ``python resampleMask.py <args>``, where <args> are
the reference image, mask to resample and a filename to store the result (the resampled mask).
"""
import argparse

import SimpleITK as sitk

parser = argparse.ArgumentParser()
parser.add_argument('image', metavar='Image', help='Reference image to resample the mask to')
parser.add_argument('mask', metavar='Mask', help='Input mask to resample')
parser.add_argument('resMask', metavar='Out', help='Filename to store resampled mask')

def main():
args = parser.parse_args()
image = sitk.ReadImage(args.image)
mask = sitk.ReadImage(args.mask)

rif = sitk.ResampleImageFilter()
rif.SetReferenceImage(image)
rif.SetOutputPixelType(mask.GetPixelID())
rif.SetInterpolator(sitk.sitkNearestNeighbor)
resMask = rif.Execute(mask)

sitk.WriteImage(resMask, args.resMask, True) # True enables compression when saving the resampled mask

if __name__ == '__main__':
main()
10 changes: 10 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ used as input for PyRadiomics. Please note that only one file location can be pr
provide the image in DICOM format, load the DICOM images using SimpleITK functionality and pass the resultant image
object instead.

**My mask was generated using a another image than my input image, can I still extract features?**

For various reasons, both image and mask must have the same geometry (i.e. same spacing, size, direction and origin)
when passed the feature classes. To this end PyRadiomics includes checks in the pipeline to ensure this is the case.
If resampling is enabled, the mask is allowed to be of a different geometry, so long as the bounding box of the Region
of Interest (ROI) represents a physical space that is within the image. If resampling is disabled, mask and image are
required to be of the same geometry. For more information on resampling, see :py:func:`~imageoperations.resampleImage`.
For more information on the mask checks, see :py:func:`~imageoperations.checkMask`. Alternatively, you could also
resample the mask to image space. An example of this is provided in ``bin\resampleMask.py``.

**What modalities does PyRadiomics support?**

PyRadiomics is not developed for one specific modality. Multiple modalities can be processed by PyRadiomics, although
Expand Down

0 comments on commit 04c4a9e

Please sign in to comment.