In [1]:
from ndreg import *
import tempfile, os, fnmatch, shutil
%matplotlib inline
In [2]:
refToken = "ara_ccf2"
refImg = imgDownload(refToken)
imgShow(refImg,vmax=500)
In [3]:
refAnnoImg = imgDownload(refToken, channel="annotation")
imgShow(refAnnoImg, vmax=1000)
In [4]:
inToken="eacker01"
nd = neurodata()
print(nd.get_channels(inToken).keys())
The STP data was acquired in color and is stored in the rgb channel. The r, g and b store ther red, green and blue channels respectively. The input STP data also has 5 resolution levels available.
In [5]:
print(nd.get_metadata(inToken)['dataset']['voxelres'].keys())
Since the r channel contains the most information while level 5 is the lowest possible resolution we'll download it using these parameters
In [6]:
inImg = imgDownload(inToken,"r",5)
In [7]:
imgShow(inImg, vmax=10000)
In [8]:
inImg = imgReorient(inImg, "lsp", "rsa")
imgShow(inImg, vmax=10000)
In [9]:
print(inImg.GetSize())
print(inImg.GetSpacing())
In [10]:
print(refImg.GetSize())
print(refImg.GetSpacing())
Thus we'll downsample them to 0.25 mm x 0.25 mm x 0.25 mm
In [11]:
spacing=[0.25,0.25,0.25]
refImg_ds = imgResample(refImg, spacing=spacing)
imgShow(refImg_ds, vmax=500)
In [12]:
inImg_ds = imgResample(inImg, spacing=spacing)
imgShow(inImg_ds, vmax=10000)
In [13]:
affine = imgAffineComposite(inImg_ds, refImg_ds, iterations=200, useMI=True, verbose=False)
Next we'll apply the affine transform to the input image
In [14]:
inImg_affine = imgApplyAffine(inImg, affine, size=refImg.GetSize(), spacing=refImg.GetSpacing())
imgShow(inImg_affine, vmax=10000)
In [15]:
outDirPath = tempfile.mkdtemp() + "/"
print(outDirPath)
Now we'll run LDDMM registration while writing the log files to the temporary directory. This will take 5 to 15 minutes.
In [16]:
inImg_ds = imgResample(inImg_affine, spacing=spacing)
(field, invField) = imgMetamorphosisComposite(inImg_ds, refImg_ds,
alphaList=[0.05, 0.02, 0.01],
useMI=True,
iterations=100,
outDirPath=outDirPath,
verbose=False)
inImg_lddmm = imgApplyField(inImg_affine, field, size=refImg.GetSize(), spacing=refImg.GetSpacing())
In [17]:
imgMetamorphosisSlicePlotter(inImg_affine, refImg, field)