In [1]:
from ndreg import *
import matplotlib
import ndio.remote.neurodata as neurodata
In [2]:
import SimpleITK as sitk
In [3]:
raw_s275 = sitk.ReadImage('/home/s275.nii')
In [4]:
ara3_atlas = sitk.ReadImage('/home/ara3.nii')
In [5]:
ara3_annotations = sitk.ReadImage('/home/ara3_annotation.nii')
In [6]:
imgShow(ara3_annotations, vmax=1000)
In [7]:
inImg = raw_s275;
refAnnoImg = ara3_annotations;
refImg = ara3_atlas;
In [8]:
refThreshold = imgPercentile(refImg, 0.99)
In [9]:
inImg.SetSpacing(np.array(inImg.GetSpacing())*1000) ###
In [10]:
inThreshold = imgPercentile(inImg, 0.95)
In [11]:
imgShow(inImg, vmax=inThreshold)
In [12]:
inOrient = "IAL"
refOrient = "RSA"
inImg = imgReorient(inImg, inOrient, refOrient)
imgShow(inImg, vmax=inThreshold)
In [13]:
inImgSize_reorient = inImg.GetSize()
inImgSpacing_reorient= inImg.GetSpacing()
In [14]:
spacing = [0.1,0.1, 0.1]
inImg_ds = imgResample(inImg, spacing)
imgShow(inImg_ds, vmax=inThreshold)
In [15]:
refImg_ds = imgResample(refImg, spacing)
imgShow(refImg_ds, vmax=refThreshold)
In [16]:
#SKIPPED: imgWrite(inImg_ds,"/home/s275_ch0_rsa_100um.img")
In [17]:
roiStart = [5.4, 1.2, 2.1]
roiSize = [4.5,6.5,7.5]
In [18]:
roiStartVoxel = (roiStart / np.array(spacing)).astype('uint16').tolist()
print(roiStartVoxel)
roiSizeVoxel = (roiSize / np.array(spacing)).astype('uint16').tolist()
print(roiSizeVoxel)
In [19]:
roiImg = sitk.Image(roiSizeVoxel,sitk.sitkUInt8)
roiImg += 255
In [20]:
emptyImg = sitk.Image(refImg_ds.GetSize(),sitk.sitkUInt8) # Create an empty image
emptyImg.CopyInformation(refImg_ds) # Copy spacing, origin and direction from reference image
refMask = sitk.Paste(emptyImg, roiImg, roiSizeVoxel, [0,0,0], roiStartVoxel)
imgShow(refMask, vmax=255)
In [21]:
refImg_ds = sitk.Mask(refImg_ds, refMask)
imgShow(refImg_ds, vmax=refThreshold)
In [22]:
threshold = imgPercentile(inImg_ds,0.95)
inMask_ds = sitk.BinaryThreshold(inImg_ds, 0, threshold, 255, 0)
imgShow(inMask_ds, vmax=255)
In [23]:
translation = -np.array(roiStart)
inAffine = [1.2,0,0,0,1.2,0,0,0,1]+translation.tolist()
print(inAffine)
imgShow(imgApplyAffine(inImg_ds, inAffine, size=refImg_ds.GetSize()),vmax = inThreshold)
In [24]:
print inImg_ds.GetSize()
In [25]:
print refImg_ds.GetSize()
In [26]:
affine = imgAffineComposite(inImg_ds, refImg_ds, inMask=inMask_ds, iterations=100, useMI=True, verbose=True, inAffine=inAffine)
In [29]:
inImg_affine = imgApplyAffine(inImg, affine, size=refImg.GetSize(), spacing=refImg.GetSpacing())
inImg_ds = imgResample(inImg_affine, spacing=spacing, size=refImg_ds.GetSize())
imgShow(inImg_affine, vmax = inThreshold)
In [30]:
inImg_ds = imgResample(inImg_affine, spacing=spacing, size=refImg_ds.GetSize())
imgShow(imgChecker(inImg_ds, refImg_ds), vmax=refThreshold)
In [ ]:
inMask_ds = imgApplyAffine(inMask_ds, affine, useNearest=True, size=refImg_ds.GetSize())
imgShow(inMask_ds, vmax=255)
imgShow(inImg_ds, vmax=inThreshold)
In [ ]:
inImg_ds = imgResample(inImg_affine, spacing=spacing, size=refImg_ds.GetSize())
(field, invField) = imgMetamorphosisComposite(inImg_ds, refImg_ds, inMask=inMask_ds, alphaList=[0.1, 0.05,0.02],
scaleList = [1.0, 1.0,1.0], useMI=True, iterations=100, verbose=True)
In [ ]:
inImg_lddmm = imgApplyField(inImg_affine, field, size=refImg.GetSize())
imgShow(inImg_lddmm, vmax=inThreshold)