sarpy.ImageProcessing package¶
Submodules¶
sarpy.ImageProcessing.resample_onto module¶
Copyright: SARlab members, UBC, Vancouver
- sarpy.ImageProcessing.resample_onto.atleast_4d(arr)[source]¶
Return at least a 4d array and fill the missing axis with 1
- Parameters
arr (numpy.ndarray) – numpy array
- Example:
>>> atleast_4d(numpy.arange(720).reshape(2,3,4,5,6)).shape (2, 3, 4, 5, 6) >>> atleast_4d(numpy.arange(120).reshape(2,3,4,5)).shape (2, 3, 4, 5) >>> atleast_4d(numpy.arange(120).reshape(2,3,20)).shape (2, 3, 20, 1) >>> atleast_4d(numpy.arange(120).reshape(2,60)).shape (2, 60, 1, 1) >>> atleast_4d(numpy.arange(120).reshape(120)).shape (120, 1, 1, 1)
- sarpy.ImageProcessing.resample_onto.resample_onto(source_fname, target_fname)[source]¶
Resamples the data in source_fname onto the grid as defined in target_fname
- Parameters
source_fname (string) – This should be pointing to a Nifti1 file. The data and header will be read and used to resample data on a new grid.
source_fname – This should also be pointing to a Nifti1 file. Only the header with the enclosed geometry information will be considered to determine the new grid to resample source_fname.data onto.
- Returns
resampled image as numpy.array
- Example:
>>> import os, nibabel >>> import sarpy >>> scan_a = sarpy.Scan("PhantomOrientation.iY1/7") >>> scan_ref = sarpy.Scan("PhantomOrientation.iY1/4") >>> fname = '3D.nii.gz' >>> fname_ref = 'coronal.nii.gz'
#>>> scan_a.pdata[0].export2nii(fname) #>>> scan_ref.pdata[0].export2nii(fname_ref) #>>> nibabel.load(fname).shape #(150, 150, 75) #>>> nibabel.load(fname_ref).shape #(256, 256, 5) #>>> new = resample_onto(fname, fname_ref) #>>> new.shape #(256, 256, 5) #>>> scan_a = sarpy.Experiment(‘NecS3Hs04’).studies[-1].scans[7] #>>> scan_ref = sarpy.Experiment(‘NecS3Hs04’).studies[-1].scans[8] >>> fname = ‘3D.nii.gz’ >>> fname_ref = ‘coronal.nii.gz’ >>> scan_a.pdata[0].export2nii(fname) >>> scan_ref.pdata[0].export2nii(fname_ref)
#>>> nibabel.load(fname).shape #(64, 64, 64, 2) #>>> nibabel.load(fname_ref).shape #(64, 128, 6, 25) #>>> new = resample_onto(fname, fname_ref) #>>> new.shape
SimpleITK.Image is either 2D or 3D not more… check out possibilty of creating SimpleITK:image orientations from visu_para
- sarpy.ImageProcessing.resample_onto.resample_onto_pdata(source_pdata, target_pdata, use_source_dims=False, replace_nan=None)[source]¶
Resamples the data
- Parameters
source_pdata (string) – This should be pointing to pdata set. The data and header (visu_pars) will be read and used to resample data on a new grid.
target_pdata (string) – This should also be pointing to a pdata set. Only the header (visu_pars) with the enclosed geometry information will be considered to determine the new grid to resample source_pdata.data onto. This means that the dimensions beyond the first 3 do not matter. It also means that image stacks with more than just one orientation will be ignored (e.g Tri- Pilot)
use_source_dims (boolean) – Ignore the matrix size derived from visu_pars and use actual matrix size as obtained from source data. Default False (good for pdata), True useful for adata that has a different shape from its parent pdata
relace_nan (int) – Replace values of NaN with 0 (and back to NaN after the resampling). The default is None (don’t do it) since this can have undesirable side effects: if the image contains the replacement value it will be changed to NaN after the resampling
- Returns
resampled image as numpy.array, or maybe ITK image? or maybe nifti1?
- Example:
>>> import sarpy >>> source_pdata = sarpy.Scan("readfidTest.ix1/7").pdata[0] >>> source_pdata.data.shape (105, 133, 5, 25) >>> target_pdata = sarpy.Scan("readfidTest.ix1/3").pdata[0] >>> target_pdata.data.shape (105, 133, 25) >>> resample_onto_pdata(source_pdata, target_pdata).shape (105, 133, 25, 25)
SimpleITK.Image is either 2D or 3D not more… check out possibilty of creating SimpleITK:image orientations from visu_para