In [1]:
from __future__ import print_function
%matplotlib inline
import matplotlib.pyplot as plt

import SimpleITK as sitk
print(sitk.Version())
from myshow import myshow
# Download data to work on
%run update_path_to_download_script
from downloaddata import fetch_data as fdata

OUTPUT_DIR = "Output"
SimpleITK Version: 1.2.4 (ITK 4.13)
Compiled: Nov 12 2019 23:05:07

This section of the Visible Human Male is about 1.5GB. To expedite processing and registration we crop the region of interest, and reduce the resolution. Take note that the physical space is maintained through these operations.

In [2]:
fixed_rgb = sitk.ReadImage(fdata("vm_head_rgb.mha"))
fixed_rgb = fixed_rgb[735:1330,204:975,:]
fixed_rgb = sitk.BinShrink(fixed_rgb,[3,3,1])
Fetching vm_head_rgb.mha
In [3]:
moving = sitk.ReadImage(fdata("vm_head_mri.mha"))
Fetching vm_head_mri.mha
In [4]:
myshow(moving)
In [5]:
# Segment blue ice
seeds = [[10,10,10]]
fixed_mask = sitk.VectorConfidenceConnected(fixed_rgb, seedList=seeds, initialNeighborhoodRadius=5, numberOfIterations=4, multiplier=8)
In [6]:
# Invert the segment and choose largest component
fixed_mask = sitk.RelabelComponent(sitk.ConnectedComponent(fixed_mask==0))==1
In [7]:
myshow(sitk.Mask(fixed_rgb, fixed_mask));
In [8]:
# pick red channel
fixed = sitk.VectorIndexSelectionCast(fixed_rgb,0)

fixed = sitk.Cast(fixed,sitk.sitkFloat32)
moving = sitk.Cast(moving,sitk.sitkFloat32)
In [9]:
initialTransform = sitk.Euler3DTransform()
initialTransform = sitk.CenteredTransformInitializer(sitk.Cast(fixed_mask,moving.GetPixelID()), moving, initialTransform, sitk.CenteredTransformInitializerFilter.MOMENTS)
print(initialTransform)
itk::simple::Transform
 Euler3DTransform (0x7f9d50d00210)
   RTTI typeinfo:   itk::Euler3DTransform<double>
   Reference Count: 1
   Modified Time: 1708
   Debug: Off
   Object Name: 
   Observers: 
     none
   Matrix: 
     1 0 0 
     0 1 0 
     0 0 1 
   Offset: [-2.50528, 0.569751, 70.3105]
   Center: [3.05258, -30.3998, -79.3064]
   Translation: [-2.50528, 0.569751, 70.3105]
   Inverse: 
     1 0 0 
     0 1 0 
     0 0 1 
   Singular: 0
   Euler's angles: AngleX=0 AngleY=0 AngleZ=0
   m_ComputeZYX = 0

In [10]:
def command_iteration(method) :
    print("{0} = {1} : {2}".format(method.GetOptimizerIteration(),
                                   method.GetMetricValue(),
                                   method.GetOptimizerPosition()),
              end='\n');
    sys.stdout.flush();
In [11]:
tx = initialTransform
R = sitk.ImageRegistrationMethod()
R.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50)
R.SetOptimizerAsGradientDescentLineSearch(learningRate=1,numberOfIterations=100)
R.SetOptimizerScalesFromIndexShift()
R.SetShrinkFactorsPerLevel([4,2,1])
R.SetSmoothingSigmasPerLevel([8,4,2])
R.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()
R.SetMetricSamplingStrategy(R.RANDOM)
R.SetMetricSamplingPercentage(0.1)
R.SetInitialTransform(tx)
R.SetInterpolator(sitk.sitkLinear)
In [12]:
import sys
R.RemoveAllCommands()
R.AddCommand( sitk.sitkIterationEvent, lambda: command_iteration(R) )
outTx = R.Execute(sitk.Cast(fixed,sitk.sitkFloat32), sitk.Cast(moving,sitk.sitkFloat32))

print("-------")
print(tx)
print("Optimizer stop condition: {0}".format(R.GetOptimizerStopConditionDescription()))
print(" Iteration: {0}".format(R.GetOptimizerIteration()))
print(" Metric value: {0}".format(R.GetMetricValue()))
0 = -0.4938320636066234 : (0.0007884690843859933, 9.115993935992577e-06, -0.00022907540392905361, -2.4506641486934644, 1.0726482770937942, 98.86135213840386)
1 = -0.6385947893820454 : (0.0031180870048248322, -0.00024973472451025056, -0.0005999326904891572, -2.143606035758025, 2.7067880265198325, 105.6310169728648)
2 = -0.6509856130885804 : (0.006827879965424329, -0.0013253144473401256, -0.0015740400610312556, -1.1329625660563745, 5.247972724286079, 99.27867045474878)
3 = -0.6998472447699149 : (0.0070835938967936316, -0.0012953029595812304, -0.0016921869946794827, -1.214627157854894, 5.449688338590283, 102.65996922969423)
4 = -0.7055128222291497 : (0.007162212002152884, -0.0012825697638981632, -0.001734586806700536, -1.2432474052760227, 5.509833599189141, 103.02508101845082)
5 = -0.7055101723436148 : (0.0072234242933462405, -0.0012724747745755148, -0.0017701060839525838, -1.2653655076170567, 5.555463923165396, 103.21216141294553)
6 = -0.7054157393478568 : (0.007279065081615429, -0.0012633346480083539, -0.0018043481429334432, -1.2854604313561833, 5.596547998629948, 103.33810876201144)
7 = -0.7054557395700655 : (0.007387294340054853, -0.0012462968884158344, -0.0018744559746281296, -1.3245948431768864, 5.676290629164056, 103.5471769585545)
8 = -0.7054275060986273 : (0.007393256372412486, -0.001245239180381504, -0.0018788394907824808, -1.3268202559614353, 5.680664508369784, 103.55805045584955)
9 = -0.705403602134381 : (0.007397050935130362, -0.0012445662653438336, -0.0018816490338551407, -1.328239135710147, 5.683449618859622, 103.56495876919698)
10 = -0.7053609424625572 : (0.007402279191209082, -0.0012436394346081675, -0.0018855374372665128, -1.3301962585252867, 5.687288254296073, 103.57446188294874)
11 = -0.7053072180692024 : (0.007410857194078621, -0.001242119853634731, -0.0018919708440082745, -1.3334174649877415, 5.693594750135532, 103.59014195736445)
12 = -0.7052576395934416 : (0.007436134748692215, -0.0012375778992539885, -0.001911052060653377, -1.3429232272408886, 5.7121665821203385, 103.63604186289501)
0 = -0.5301865301933348 : (0.007264153623112432, -0.0012970469450164454, -0.0018109684650209157, -1.2587570244375499, 5.600270663655044, 103.97307474975935)
1 = -0.5308728398444801 : (0.007385112338472612, -0.0013137399140509618, -0.001905322612725405, -1.276097416873967, 5.7011200808085345, 104.22715556691739)
2 = -0.5310200926403805 : (0.007895464749576414, -0.0013559755648252282, -0.0023946982062081268, -1.3801271119349034, 6.135224694652677, 104.17329085023316)
3 = -0.5320350597698182 : (0.008099336165700197, -0.0014802648756018222, -0.0031842925699488256, -1.4768220529291252, 6.4504866771388825, 104.06344569475108)
4 = -0.5324500685084689 : (0.008085595324890412, -0.0014901577672268341, -0.003227015191900899, -1.4776981569749288, 6.453162507878792, 104.10780996972478)
5 = -0.532410776129525 : (0.008048990101312027, -0.00151577013355796, -0.003340240487286641, -1.4804482787032156, 6.459866198419477, 104.15639744054802)
6 = -0.5324234022297232 : (0.007946941141972402, -0.0015817724878536765, -0.003643757049909391, -1.4891994924854617, 6.475082641963282, 104.08347873202275)
7 = -0.5325182622870093 : (0.007915198171643503, -0.0016029153574471842, -0.0037330084175892066, -1.4902568473086912, 6.4788045107967775, 104.1516558932755)
8 = -0.5324718119131144 : (0.007784893503683851, -0.00168407552881333, -0.004089387350286454, -1.497113314289813, 6.491073518774487, 104.08926129572238)
9 = -0.532549133260804 : (0.007748192666661494, -0.0017077603220642717, -0.004187574781969946, -1.4977985872959518, 6.49413043020349, 104.1572370331905)
10 = -0.5325433619824078 : (0.007661972084180833, -0.0017607389570313216, -0.004414000618112439, -1.5010141628070086, 6.499637587523841, 104.09327205957361)
11 = -0.5326118702417717 : (0.007628917751727332, -0.0017818372055447846, -0.004501241661853208, -1.5015283004031723, 6.502022015089012, 104.14879080812163)
12 = -0.5326193328854125 : (0.007538921792185131, -0.0018369370124621893, -0.00473428082516517, -1.504253489875741, 6.507033193978628, 104.10733749845163)
13 = -0.5326758536759729 : (0.007502592376158602, -0.0018594479076398988, -0.004827713295359416, -1.5048657375883152, 6.509135254206996, 104.1466778508694)
14 = -0.5326714529448527 : (0.007356032514037034, -0.0019496840904617047, -0.005203609724524734, -1.5085563245070333, 6.51631337938488, 104.08388408446018)
15 = -0.5327314997017304 : (0.00731887228051077, -0.0019737221767140087, -0.00529941066949841, -1.508725206397848, 6.518532815044126, 104.15526353871701)
16 = -0.5327298224546847 : (0.00721190353035848, -0.00204039210157878, -0.005573178961554179, -1.511269906534221, 6.523000169852378, 104.0624142085985)
17 = -0.5328070379316563 : (0.007189635805677322, -0.0020550715236330166, -0.005630481085354977, -1.511227514655735, 6.524364404818061, 104.12220513665977)
18 = -0.532807923562015 : (0.0071798155669131995, -0.0020612990810908323, -0.005655555715598267, -1.5113724483131248, 6.524832226761675, 104.12578082456037)
19 = -0.5328142975313359 : (0.007171448662460544, -0.0020665716242859646, -0.005676793326296284, -1.5115022837705365, 6.5252062967680295, 104.1276470314575)
20 = -0.5328052416466585 : (0.007139631532348924, -0.002086718512117799, -0.005757587959448272, -1.5119869538833008, 6.526626130857385, 104.13170911685121)
21 = -0.5328036360001549 : (0.006982204000922928, -0.002186630765773665, -0.006157425646656282, -1.5144829098800043, 6.53346029425307, 104.12166628474833)
22 = -0.5328741231611553 : (0.0063820913523654895, -0.0025738159228418747, -0.007688523998055439, -1.522675608377514, 6.560946373464795, 104.26943132784103)
23 = -0.533039972461893 : (0.006297429981743231, -0.0026281107088268374, -0.007906186747525499, -1.5280167270835054, 6.5616404212703925, 103.77726594439119)
24 = -0.5332929282430959 : (0.0062908109726979205, -0.0026331043612456578, -0.0079225702362809, -1.5275056552404775, 6.562296801512822, 103.86178820270196)
25 = -0.533294170754813 : (0.006280919916872348, -0.002640285506247858, -0.00794737425257317, -1.527004653780746, 6.5632046590228965, 103.95999715317689)
26 = -0.5332908817842071 : (0.006276974700350127, -0.0026431373078770995, -0.007957463061536052, -1.526887425825399, 6.563528863479995, 103.98511221694893)
27 = -0.5332976932478377 : (0.006272810710571466, -0.0026461436061653875, -0.007968101725232102, -1.5267799449243793, 6.56384803679953, 104.00740674319499)
28 = -0.533284895017134 : (0.00626910917948415, -0.0026488127108402586, -0.007977562800127569, -1.5267002909993685, 6.564115581497912, 104.02395985500762)
29 = -0.5332696448101707 : (0.006266440093961133, -0.002650771828157527, -0.007984392819578601, -1.5266428672116716, 6.564301085815193, 104.0342008530915)
30 = -0.5332654161497206 : (0.006264691529004304, -0.002652075243304976, -0.007988866618795455, -1.526603602995742, 6.5644201930087975, 104.04017919728632)
31 = -0.5332630314569115 : (0.006263907408966677, -0.0026526529437828506, -0.007990864775989714, -1.5265881178996996, 6.564471469941654, 104.04266216225436)
32 = -0.5332546511690232 : (0.006262950308242946, -0.002653357951109488, -0.007993303230998736, -1.526569659380883, 6.564533494250085, 104.04559331495345)
0 = -0.4492844737615327 : (0.006272686053801062, -0.0026463905775645164, -0.007968368885366263, -1.5266208997102086, 6.563874737015774, 104.00243521218964)
1 = -0.4492826474657344 : (0.006272614403654104, -0.0026465324485214266, -0.007968522285929364, -1.5265294655814197, 6.5638901341932225, 103.99959197045537)
2 = -0.4492831053343391 : (0.0062724563025979285, -0.002646845014923808, -0.007968860286899077, -1.526327912748097, 6.563924068747901, 103.99334269078807)
3 = -0.4492798465025481 : (0.006272285037138167, -0.0026471815464200244, -0.007969223536331303, -1.5261109169602762, 6.5639604274408905, 103.98666363774299)
4 = -0.4492743536161589 : (0.006271787991897116, -0.0026481567035681547, -0.007970274715769766, -1.525481942546499, 6.5640658947702475, 103.96745090116325)
5 = -0.44927252739811857 : (0.006271491790927513, -0.0026487358572290943, -0.00797089702270916, -1.5251078348434068, 6.564128962078229, 103.95626915107606)
6 = -0.44927151375012836 : (0.006271476498609555, -0.0026487657522419983, -0.007970929069931122, -1.525088515798745, 6.5641322324441616, 103.9556992182386)
7 = -0.4492711111999151 : (0.006271467430618144, -0.0026487834691864423, -0.007970948066626024, -1.5250770652182961, 6.56413417116925, 103.95536160920103)
8 = -0.44927095381804155 : (0.006271444835272529, -0.0026488276113086746, -0.007970995396469411, -1.5250485347501423, 6.564139002183052, 103.95452074025471)
-------
itk::simple::Transform
 Euler3DTransform (0x7f9d50d00210)
   RTTI typeinfo:   itk::Euler3DTransform<double>
   Reference Count: 3
   Modified Time: 5124186
   Debug: Off
   Object Name: 
   Observers: 
     none
   Matrix: 
     0.999965 0.00796813 -0.00269629 
     -0.00798486 0.999949 -0.00625134 
     0.00264634 0.00627264 0.999977 
   Offset: [-1.49812, 6.09092, 104.183]
   Center: [3.05258, -30.3998, -79.3064]
   Translation: [-1.52662, 6.56387, 104.002]
   Inverse: 
     0.999965 -0.00798486 0.00264634 
     0.00796813 0.999949 0.00627264 
     -0.00269629 -0.00625134 0.999977 
   Singular: 0
   Euler's angles: AngleX=0.00627269 AngleY=-0.00264639 AngleZ=-0.00796837
   m_ComputeZYX = 0

Optimizer stop condition: GradientDescentLineSearchOptimizerv4Template: Convergence checker passed at iteration 9.
 Iteration: 9
 Metric value: -0.4492844737615327
In [13]:
tx.AddTransform(sitk.Transform(3,sitk.sitkAffine))

R.SetOptimizerAsGradientDescentLineSearch(learningRate=1,numberOfIterations=100)
R.SetOptimizerScalesFromIndexShift()
R.SetShrinkFactorsPerLevel([2,1])
R.SetSmoothingSigmasPerLevel([4,1])
R.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()
R.SetInitialTransform(tx)
In [14]:
outTx = R.Execute(sitk.Cast(fixed,sitk.sitkFloat32), sitk.Cast(moving,sitk.sitkFloat32))
R.GetOptimizerStopConditionDescription()
0 = -0.5347705894701951 : (0.9935491960906018, 0.0010244477246398466, -0.00018712504404234346, 0.0012821354876719146, 0.9958949605465209, -0.00015292310443917024, -0.002915238951579409, -0.015140978484508245, 1.0025677700977367, 0.04203999617438272, 0.028711655113850133, 0.709970241304767)
1 = -0.537657217075003 : (0.9925205198448369, 0.0012164324026988406, -0.00021125461708909125, 0.0015419139824131695, 0.9950436905549638, -0.0002495845433685679, -0.001613111802551819, -0.009338801650009786, 1.0036338902966704, 0.05604757845793676, 0.11450803586669323, -0.505823462175846)
2 = -0.5397797268750215 : (0.9924373646812108, 0.001230823337400288, -0.00021272594813850508, 0.0015590089452871263, 0.994989350559764, -0.0002531352452381969, -0.0015541217096985104, -0.00938730070188818, 1.0036236449758278, 0.05686138975989303, 0.11709708619858393, -0.44300957458203555)
3 = -0.5397330184310062 : (0.9923513894753446, 0.001245933585372603, -0.0002140772574440882, 0.0015767462315546042, 0.9949330498410498, -0.000256655712365532, -0.0014975977597499678, -0.009427990144345982, 1.0036177573321283, 0.05760072200365054, 0.11969587687259631, -0.38589268007121846)
4 = -0.5397137098467241 : (0.9922659046053379, 0.0012611375989336213, -0.0002153124475079074, 0.0015944625451069323, 0.9948768428496655, -0.0002599643477343558, -0.0014447396762084833, -0.009460887593658797, 1.0036162844960472, 0.05826320196837963, 0.12218711237794827, -0.33589578954090227)
5 = -0.539706713378011 : (0.992161452254395, 0.0012798542980973016, -0.00021674691741867944, 0.0016161125622988326, 0.9948080048153244, -0.0002638315992104458, -0.0013835508992116048, -0.009493232068350755, 1.0036193645616107, 0.05900482133861869, 0.12512786751077876, -0.2820059266300868)
6 = -0.5396862735669599 : (0.9919962643646794, 0.0013097525347187567, -0.0002188052205550852, 0.0016503070910908711, 0.9946990152955184, -0.00026949890557843707, -0.0012958685712166772, -0.009529957591651579, 1.0036339686331468, 0.06003379559536627, 0.12953080972530087, -0.2100367050418263)
7 = -0.5396752064609306 : (0.9918044315133009, 0.0013448202145315174, -0.00022127694474435898, 0.0016901199864534416, 0.9945726719832398, -0.0002752002328116512, -0.001208712369796434, -0.00955032217890834, 1.003666474048914, 0.061138793485969734, 0.13415395504728858, -0.14801013045663652)
8 = -0.5396837602254982 : (0.9910920015551159, 0.001475996898671847, -0.00023039753086453427, 0.0018380195603529262, 0.9941034745722002, -0.00029351869011703946, -0.0009477313743127098, -0.009566430449550667, 1.003842994669176, 0.06481407162422714, 0.1495440365725581, 0.00792535133385186)
9 = -0.539724922613781 : (0.9876001040961988, 0.002141199604900943, -0.00026835306592575047, 0.002567232397587945, 0.9918153962712309, -0.00033527148669838943, -0.0006137902617865175, -0.009544964304623163, 1.0052579066319396, 0.07401707101520277, 0.19468794171704307, -0.09477445913407813)
10 = -0.5410501941879916 : (0.9864162021180595, 0.0023483338302542024, -0.0002894862313728616, 0.002793780993509686, 0.9910843956406878, -0.00030962412948757386, -0.00025491692635909484, -0.011275784939806825, 1.0053129580709868, 0.08238216764812813, 0.18303422751621565, 0.2751713003684557)
11 = -0.5411319285129291 : (0.9846114262149624, 0.002702592681750009, -0.0003084918082672803, 0.0031645978556399503, 0.9898889717519817, -0.0002579175762058393, -0.00017258681364118868, -0.011268894709633867, 1.006084306855246, 0.08467828665194524, 0.16899460406531022, -0.4205503650084146)
12 = -0.5421104025212852 : (0.9844114772176127, 0.0027356141126580096, -0.000312744887506214, 0.003199233610577441, 0.989761557293771, -0.0002548546780687873, -7.181885306471012e-05, -0.011567591063147444, 1.005983619320425, 0.08631524418919163, 0.16918727404173334, -0.22943484323943017)
13 = -0.5421349069831599 : (0.9843131532757918, 0.0027523766417166385, -0.0003147405097573246, 0.0032166530149068885, 0.9896971591246108, -0.0002528900180456762, -4.0019359562015935e-05, -0.011662001995721219, 1.0059605889893048, 0.08700343876942265, 0.1690782487681294, -0.17021126858187033)
14 = -0.5421481098480312 : (0.9841991359194706, 0.0027720504127083743, -0.0003171107543479301, 0.003236997537564057, 0.9896219183035622, -0.00025028620035985323, -6.955085828906926e-06, -0.011754996694697279, 1.0059419899668023, 0.08778239984452263, 0.1688031916946609, -0.11429964853522677)
15 = -0.5421431891556366 : (0.9840827403857367, 0.0027924464537678467, -0.0003194983617447512, 0.003257824480523252, 0.9895447390970183, -0.00024720546398195286, 2.5628564388071474e-05, -0.011836165696169777, 1.005930391870808, 0.08853247683755736, 0.16834033575940419, -0.06969372520263005)
16 = -0.5421341938163995 : (0.9839819936888424, 0.002810316284131218, -0.00032156563501044874, 0.0032758854293863868, 0.989477609941012, -0.0002442136673657116, 5.252383715019933e-05, -0.011896599258016567, 1.00592516161746, 0.08915910269291316, 0.1678045915292473, -0.03959402064190691)
17 = -0.5421138889349352 : (0.983941060639059, 0.00281757194179244, -0.00032243720611273665, 0.0032832033987217654, 0.9894501915906126, -0.00024292190849938428, 6.351739889677306e-05, -0.01191794460100231, 1.005924398904918, 0.08941858549004723, 0.1675542868677367, -0.029713257537099885)
18 = -0.5421080009673316 : (0.9839213968497457, 0.002821073776609736, -0.00032284976569521193, 0.003286722516789787, 0.9894369985026252, -0.00024228527248403654, 6.868160627782402e-05, -0.011927889497739031, 1.0059241405874242, 0.08954021831480934, 0.16742776607906712, -0.025309247541014025)
19 = -0.5421018648076805 : (0.9839078616013105, 0.0028234842848835883, -0.0003231308169693165, 0.0032891390930077486, 0.9894279133138263, -0.0002418410931445759, 7.225017954908268e-05, -0.01193459867326969, 1.0059240187869372, 0.08962277188039304, 0.16733837100311955, -0.02238836720404884)
20 = -0.5421002893487241 : (0.9838833672768222, 0.002827848723953733, -0.000323639821626461, 0.0032935110883930904, 0.9894114649944226, -0.00024103279876631263, 7.868273174322049e-05, -0.011946577344486568, 1.0059238739211986, 0.0897718762948533, 0.16717459781928337, -0.01724009879580018)
0 = -0.40231640316658673 : (0.9841947796714521, 0.002772162067379303, -0.0003172603218978142, 0.0032372520316412672, 0.9896204116045577, -0.00025056869172155607, 5.91845318496758e-06, -0.011754452161190374, 1.0059452278708756, 0.08790638404062473, 0.16891502751904264, -0.11637022331176165)
1 = -0.40231675320166266 : (0.9841817110157826, 0.0027724969749331717, -0.0003177090127671678, 0.003238014742690191, 0.9896158917912586, -0.0002514163952045743, 4.4507823331382976e-05, -0.011752848628624482, 1.0059549258272975, 0.08827812866645719, 0.16925059180265184, -0.12255845323059568)
2 = -0.4023167573031705 : (0.9841642288884099, 0.0027729453548687114, -0.0003183084602231381, 0.003239034139747645, 0.9896098461113163, -0.00025255092762172036, 9.605065348328813e-05, -0.011750828828953171, 1.0059678413948119, 0.08877447083822808, 0.16969971911486567, -0.13074594753576976)
3 = -0.4023151844414466 : (0.9841619463526962, 0.002773004125064369, -0.000318386564832991, 0.003239166980074606, 0.9896090572371444, -0.00025269916195781034, 0.00010276099152840552, -0.011750583998515373, 1.0059695197711236, 0.08883909023423542, 0.1697583996149019, -0.13179991950073233)
4 = -0.4023126996433995 : (0.9841601878872267, 0.00277304941128788, -0.0003184468008253413, 0.003239269320023796, 0.9896084494819989, -0.0002528133752586904, 0.00010792915807255005, -0.011750396983461444, 1.005970812366685, 0.08888888315341455, 0.16980361177332562, -0.13261072042665212)
5 = -0.4023122709643342 : (0.9841601856491936, 0.002773049468967022, -0.00031844687745468916, 0.003239269450285102, 0.9896084487085276, -0.0002528135206075842, 0.000107935734117576, -0.011750396747007926, 1.0059708140111014, 0.08888894650232872, 0.169803669313179, -0.13261175095409883)
6 = -0.40231301886789644 : (0.9841601856436902, 0.0027730494691088573, -0.0003184468776431212, 0.0032392694506054175, 0.9896084487066256, -0.0002528135209650025, 0.00010793575028823569, -0.011750396746426514, 1.005970814015145, 0.08888894665810453, 0.16980366945467157, -0.13261175348812626)
7 = -0.4023130188667128 : (0.9841601856428438, 0.002773049469130672, -0.0003184468776721025, 0.0032392694506546828, 0.989608448706333, -0.0002528135210199742, 0.00010793575277531728, -0.011750396746337093, 1.005970814015767, 0.08888894668206317, 0.16980366947643344, -0.13261175387786503)
8 = -0.40231301886696663 : (0.9841601856425406, 0.002773049469138485, -0.00031844687768248263, 0.003239269450672328, 0.9896084487062282, -0.00025281352103966324, 0.00010793575366610856, -0.011750396746305064, 1.0059708140159898, 0.08888894669064437, 0.16980366948422781, -0.1326117540174567)
9 = -0.4023130188658449 : (0.9841601856417792, 0.0027730494691581087, -0.0003184468777085534, 0.0032392694507166458, 0.9896084487059651, -0.00025281352108911436, 0.00010793575590342239, -0.011750396746224622, 1.0059708140165493, 0.08888894671219695, 0.1698036695038042, -0.13261175436805556)
10 = -0.4023130188644502 : (0.9841601856415451, 0.0027730494691641425, -0.00031844687771656925, 0.003239269450730272, 0.9896084487058842, -0.0002528135211043188, 0.00010793575659131629, -0.011750396746199888, 1.0059708140167214, 0.0888889467188236, 0.16980366950982326, -0.13261175447585216)
11 = -0.40231301886492166 : (0.9841601856415321, 0.002773049469164478, -0.00031844687771701523, 0.00323926945073103, 0.9896084487058796, -0.0002528135211051648, 0.00010793575662959179, -0.011750396746198512, 1.005970814016731, 0.08888894671919231, 0.16980366951015816, -0.13261175448185014)
12 = -0.4023130188644326 : (0.984160185641518, 0.0027730494691648416, -0.0003184468777174982, 0.003239269450731851, 0.9896084487058747, -0.0002528135211060808, 0.00010793575667103543, -0.011750396746197022, 1.0059708140167414, 0.08888894671959155, 0.16980366951052078, -0.13261175448834459)
13 = -0.40231301886467513 : (0.9841601856415093, 0.002773049469165066, -0.0003184468777177962, 0.0032392694507323576, 0.9896084487058717, -0.00025281352110664607, 0.00010793575669660924, -0.011750396746196103, 1.0059708140167478, 0.08888894671983791, 0.16980366951074455, -0.13261175449235213)
14 = -0.40231301886408694 : (0.9841601856415007, 0.0027730494691652896, -0.0003184468777180937, 0.0032392694507328633, 0.9896084487058687, -0.00025281352110721034, 0.00010793575672213976, -0.011750396746195185, 1.0059708140167543, 0.08888894672008385, 0.16980366951096795, -0.1326117544963529)
15 = -0.40231301886389387 : (0.9841601856414858, 0.0027730494691656743, -0.00031844687771860467, 0.003239269450733732, 0.9896084487058636, -0.0002528135211081795, 0.00010793575676598895, -0.011750396746193608, 1.0059708140167651, 0.08888894672050626, 0.16980366951135162, -0.1326117545032243)
16 = -0.40231301886388504 : (0.9841601856414747, 0.0027730494691659605, -0.00031844687771898496, 0.003239269450734378, 0.9896084487058597, -0.0002528135211089008, 0.00010793575679862145, -0.011750396746192436, 1.0059708140167734, 0.08888894672082062, 0.16980366951163714, -0.13261175450833798)
17 = -0.4023130188635225 : (0.9841601856414636, 0.0027730494691662463, -0.0003184468777193646, 0.0032392694507350234, 0.9896084487058558, -0.00025281352110962085, 0.00010793575683119872, -0.011750396746191265, 1.0059708140167816, 0.08888894672113444, 0.1698036695119222, -0.132611754513443)
18 = -0.4023130188635025 : (0.9841601856414292, 0.0027730494691671336, -0.0003184468777205434, 0.0032392694507370275, 0.989608448705844, -0.0002528135211118568, 0.00010793575693235912, -0.011750396746187627, 1.0059708140168069, 0.08888894672210894, 0.16980366951280734, -0.13261175452929538)
19 = -0.40231301886146525 : (0.984160185641342, 0.00277304946916938, -0.00031844687772352776, 0.0032392694507421007, 0.9896084487058139, -0.0002528135211175175, 0.00010793575718846718, -0.01175039674617842, 1.0059708140168708, 0.08888894672457609, 0.16980366951504827, -0.13261175456942886)
20 = -0.4023130188614115 : (0.9841601856412658, 0.002773049469171343, -0.0003184468777261356, 0.0032392694507465338, 0.9896084487057876, -0.0002528135211224641, 0.00010793575741226346, -0.011750396746170372, 1.0059708140169268, 0.08888894672673198, 0.16980366951700648, -0.13261175460449892)
21 = -0.4023130188600253 : (0.9841601856411454, 0.0027730494691744468, -0.00031844687773025914, 0.0032392694507535433, 0.9896084487057459, -0.0002528135211302857, 0.00010793575776613452, -0.01175039674615765, 1.0059708140170154, 0.0888889467301409, 0.16980366952010284, -0.13261175465995237)
22 = -0.4023130188598801 : (0.9841601856410536, 0.002773049469176813, -0.00031844687773340284, 0.003239269450758887, 0.9896084487057142, -0.0002528135211362487, 0.00010793575803591848, -0.011750396746147949, 1.0059708140170829, 0.0888889467327398, 0.16980366952246345, -0.13261175470222894)
23 = -0.40231301885906073 : (0.9841601856408211, 0.002773049469182804, -0.0003184468777413618, 0.0032392694507724167, 0.9896084487056338, -0.00025281352115134523, 0.00010793575871893124, -0.011750396746123392, 1.0059708140172536, 0.08888894673931942, 0.16980366952843978, -0.13261175480926063)
24 = -0.4023130188579933 : (0.9841601856406776, 0.0027730494691865005, -0.0003184468777462731, 0.0032392694507807655, 0.9896084487055842, -0.0002528135211606609, 0.00010793575914040088, -0.011750396746108237, 1.005970814017359, 0.08888894674337953, 0.1698036695321276, -0.13261175487530713)
25 = -0.40231301885789844 : (0.9841601856405344, 0.002773049469190191, -0.000318446877751176, 0.0032392694507891, 0.9896084487055347, -0.0002528135211699608, 0.00010793575956115704, -0.011750396746093109, 1.0059708140174644, 0.08888894674743278, 0.16980366953580922, -0.13261175494124183)
26 = -0.4023130188567548 : (0.984160185640446, 0.0027730494691924684, -0.00031844687775420147, 0.003239269450794243, 0.9896084487055041, -0.00025281352117569955, 0.00010793575982079485, -0.011750396746083774, 1.0059708140175292, 0.08888894674993393, 0.16980366953808104, -0.13261175498192845)
27 = -0.40231301885571874 : (0.9841601856404093, 0.0027730494691934147, -0.0003184468777554584, 0.0032392694507963797, 0.9896084487054915, -0.0002528135211780837, 0.00010793575992866091, -0.011750396746079896, 1.005970814017556, 0.08888894675097303, 0.16980366953902487, -0.13261175499883163)
28 = -0.4023130188551369 : (0.9841601856403727, 0.0027730494691943592, -0.0003184468777567132, 0.0032392694507985126, 0.9896084487054788, -0.0002528135211804638, 0.00010793576003634437, -0.011750396746076024, 1.005970814017583, 0.08888894675201037, 0.1698036695399671, -0.13261175501570618)
29 = -0.4023130188545105 : (0.98416018564035, 0.002773049469194942, -0.00031844687775748747, 0.003239269450799829, 0.989608448705471, -0.0002528135211819325, 0.00010793576010279307, -0.011750396746073635, 1.0059708140175996, 0.08888894675265048, 0.1698036695405485, -0.13261175502611905)
30 = -0.40231301885403453 : (0.9841601856403414, 0.0027730494691951646, -0.00031844687775778275, 0.0032392694508003306, 0.989608448705468, -0.0002528135211824926, 0.00010793576012813481, -0.011750396746072724, 1.005970814017606, 0.0888889467528946, 0.16980366954077025, -0.13261175503009023)
Out[14]:
'GradientDescentLineSearchOptimizerv4Template: Convergence checker passed at iteration 31.'
In [15]:
resample = sitk.ResampleImageFilter()
resample.SetReferenceImage(fixed_rgb)
resample.SetInterpolator(sitk.sitkBSpline)
resample.SetTransform(outTx)
resample.AddCommand(sitk.sitkProgressEvent, lambda: print("\rProgress: {0:03.1f}%...".format(100*resample.GetProgress()),end=''))
resample.AddCommand(sitk.sitkProgressEvent, lambda: sys.stdout.flush())
resample.AddCommand(sitk.sitkEndEvent, lambda: print("Done"))
out = resample.Execute(moving)
Progress: 100.0%...Done
In [16]:
out_rgb = sitk.Cast( sitk.Compose( [sitk.RescaleIntensity(out)]*3), sitk.sitkVectorUInt8)
vis_xy = sitk.CheckerBoard(fixed_rgb, out_rgb, checkerPattern=[8,8,1])
vis_xz = sitk.CheckerBoard(fixed_rgb, out_rgb, checkerPattern=[8,1,8])
vis_xz = sitk.PermuteAxes(vis_xz, [0,2,1])
In [17]:
myshow(vis_xz,dpi=30)
In [18]:
import os

sitk.WriteImage(out, os.path.join(OUTPUT_DIR, "example_registration.mha"))
sitk.WriteImage(vis_xy, os.path.join(OUTPUT_DIR, "example_registration_xy.mha"))
sitk.WriteImage(vis_xz, os.path.join(OUTPUT_DIR, "example_registration_xz.mha"))