-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STYL: Add FAQ for image and mask of different geometry
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
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
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
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() |
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