Registration Example¶
In [1]:
%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: 2.4.0 (ITK 5.4) Compiled: Aug 15 2024 01:21:37
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::Euler3DTransform Euler3DTransform (0x7f8df87dcfc0) RTTI typeinfo: itk::Euler3DTransform<double> Reference Count: 1 Modified Time: 3728 Debug: Off Object Name: Observers: none Matrix: 1 0 0 0 1 0 0 0 1 Offset: [-0.305777, 2.55523, 135.031] Center: [0.853078, -32.3853, -144.027] Translation: [-0.305777, 2.55523, 135.031] Inverse: 1 0 0 0 1 0 0 0 1 Singular: 0 AngleX: 0 AngleY: 0 AngleZ: 0 ComputeZYX: Off
In [10]:
def command_iteration(method):
print(
f"{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)
# specifying a seed eliminates registration variability associated with the
# random sampling
R.SetMetricSamplingPercentage(percentage=0.1, seed=42)
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(f"Optimizer stop condition: {R.GetOptimizerStopConditionDescription()}")
print(f" Iteration: {R.GetOptimizerIteration()}")
print(f" Metric value: {R.GetMetricValue()}")
0 = -0.7633063775373199 : (-0.0007251069363556011, -0.0004616650065359306, -0.00029872387211812005, -0.06285427361028123, 2.7316499067940554, 109.7703328160343)
1 = -1.1826751740226433 : (-0.0011684068679123868, -0.0008655481622207755, -0.00046279630880065466, -0.30863411589667533, 2.940196913878562, 107.77275330345998)
2 = -1.1860220026357704 : (-0.002246494426982868, -0.0017899175822320085, -0.000786754457434835, -0.7467617667792382, 3.3673346459401876, 109.49425731262846)
3 = -1.2009357450679656 : (-0.002341740740537487, -0.0018407596235358388, -0.0008253641732948884, -0.753240492974779, 3.3904028961788812, 109.08275356856258)
4 = -1.2015891475478269 : (-0.0024923686885144573, -0.0019244612147116405, -0.0008860834831289548, -0.766393621470172, 3.4269550263805386, 108.59996629816861)
5 = -1.2015458441069766 : (-0.002720248924479156, -0.002055953250176367, -0.000977055382048611, -0.7888867189246096, 3.4828483959313936, 108.19536711229534)
6 = -1.2011280524310775 : (-0.003731092760915537, -0.002649496200497969, -0.0013736111964535093, -0.8887844499139288, 3.7179029406428747, 107.8555022013922)
7 = -1.2025209799957448 : (-0.005267615447186065, -0.003448821792621109, -0.002000225362384655, -0.9480401025275874, 3.963201740079521, 109.11659258148521)
8 = -1.2078375789568716 : (-0.005395885489474075, -0.00350538757747309, -0.002058325699255972, -0.939383650637257, 3.9726453861356177, 108.58393446133363)
9 = -1.20680147640917 : (-0.005679610734367443, -0.0036401125632585336, -0.0021854480940744683, -0.928426945514153, 3.9961813547998197, 107.96676271497321)
10 = -1.2058655654975297 : (-0.00712927001897187, -0.004367197992651119, -0.0028289664318511456, -0.9317740196460933, 4.103454126226884, 108.36584709463266)
11 = -1.2085064198256712 : (-0.007238637251156347, -0.004419943658296416, -0.0028784344611683145, -0.9289868166177442, 4.1076954846641724, 108.2202087177618)
12 = -1.2079680377805275 : (-0.007467901966569997, -0.004531731897060068, -0.0029828366973854467, -0.925482453479957, 4.1166252411916755, 108.059458741962)
13 = -1.2079981727303208 : (-0.008523401769814098, -0.005059094200085747, -0.0034658624110496788, -0.9153177122475152, 4.155765455543679, 108.00123084365292)
14 = -1.2094271121051519 : (-0.013700205996786726, -0.007681486346526628, -0.005843482620457692, -0.8951464923462884, 4.284194797331301, 108.87339484269252)
15 = -1.2146166621427077 : (-0.013918054381587422, -0.007779634163969451, -0.005949465286491562, -0.8850059409098496, 4.275780975633542, 107.97700647935041)
16 = -1.216046748867661 : (-0.015065865171183, -0.00836680743576619, -0.006476382369684923, -0.8695450423789585, 4.259833679592699, 108.14950817518952)
17 = -1.2170585826722384 : (-0.015329634315603434, -0.008502088725576201, -0.006598256500151941, -0.8657529980818636, 4.256360122763856, 107.97379944896835)
18 = -1.217483644668267 : (-0.016454213545947147, -0.009071689852691607, -0.007112488730172214, -0.8598775140644564, 4.243829677915899, 108.13470185237502)
19 = -1.2184518267561761 : (-0.016695233511129528, -0.009193383589260657, -0.0072245200043835976, -0.8558271846926528, 4.241860992795353, 107.97580342058619)
20 = -1.2190281442189845 : (-0.01778402725915739, -0.009741353014548872, -0.0077250497505656004, -0.8493353713233486, 4.233703067229879, 108.094174852134)
21 = -1.220086049731362 : (-0.01818173534540933, -0.009941744858576828, -0.00791064019871354, -0.8434132122109292, 4.231386030686689, 107.88910464009791)
22 = -1.2202306718738651 : (-0.01856176386384629, -0.01013388458857781, -0.008086014564741888, -0.8431634195613762, 4.229321684611176, 108.08064910686186)
23 = -1.220979298804922 : (-0.018931401213665194, -0.010319424682808338, -0.00825916010395821, -0.8379008983353405, 4.227534227490665, 107.90366567934639)
24 = -1.2210421126756836 : (-0.01930771987688902, -0.010508992541526088, -0.008433838667169806, -0.8375437553115398, 4.225822801474204, 108.06042353993958)
25 = -1.2215783352690694 : (-0.020100934009036012, -0.010906031584138845, -0.008807166642511747, -0.826953351624983, 4.22249288919364, 107.73745787450426)
26 = -1.221669960752691 : (-0.02033957482300158, -0.011026128317036568, -0.008917424227681913, -0.8290154388930701, 4.221525915046478, 108.03360152563515)
27 = -1.222561276862145 : (-0.020518115812364228, -0.01111504710270918, -0.009002047288485969, -0.8269708638926245, 4.220924277487292, 107.97872681644725)
28 = -1.2226516584675513 : (-0.021405086037475207, -0.011557839131059348, -0.00942046086298214, -0.8199449276486448, 4.217743889863377, 107.96515220031102)
29 = -1.2233584044558417 : (-0.025739595767001036, -0.013701906280519066, -0.011471877207533433, -0.801050611462516, 4.19436985601266, 108.02871228247965)
30 = -1.2267961030335954 : (-0.025883731611276977, -0.013767333377773614, -0.01154275191563029, -0.7977631237831576, 4.193343637192819, 107.93921752963927)
31 = -1.2268815507093054 : (-0.02660597015165947, -0.014096316266291915, -0.01189410094443508, -0.7879447864656154, 4.1867882055407755, 107.87943504619788)
32 = -1.2273235859206544 : (-0.029505535295043257, -0.015427503871464812, -0.01329811215399323, -0.7781362076810635, 4.1631071890634885, 108.62203307324602)
33 = -1.229529175633195 : (-0.02960848312090092, -0.015470017078396476, -0.01334506873239597, -0.770866285884412, 4.158645835128397, 108.24439449680501)
34 = -1.2302114925619794 : (-0.029862087250846214, -0.015577503458488249, -0.01346357498725145, -0.7612585029442738, 4.1527034974025625, 107.79040154442849)
35 = -1.2301591558795308 : (-0.03062709626325489, -0.015933744610468318, -0.013831397938209516, -0.7675167858734793, 4.151491983020454, 108.30208895551371)
36 = -1.2312406213288876 : (-0.030891295547626416, -0.016040523575365517, -0.013952916189868044, -0.7550892428659838, 4.144000209465257, 107.75781029361436)
37 = -1.2311437318021963 : (-0.03141955480693099, -0.016282283013222515, -0.014205787633016114, -0.7618180296743098, 4.145023995366812, 108.19402682401589)
38 = -1.2319024368622205 : (-0.0315099353182398, -0.016319746385105586, -0.014247383484092041, -0.7583745881303741, 4.142845695303596, 108.05176275822623)
39 = -1.2318291510412673 : (-0.03188228376297917, -0.01647938134123078, -0.014420532610112571, -0.7497099787590005, 4.136036689484275, 107.7411059242828)
40 = -1.231818495119285 : (-0.03254087681924303, -0.01677691342886287, -0.014732971449253517, -0.7580860810939125, 4.137036530887776, 108.34130810012441)
41 = -1.232626985870402 : (-0.032704475281807366, -0.016840308107849672, -0.014805587885414504, -0.7489951069039189, 4.131368788224938, 107.98230141683209)
42 = -1.2330783231486149 : (-0.03292636615620926, -0.016935396308476756, -0.01490942423602523, -0.745828733294527, 4.128660232973735, 107.87091219872896)
43 = -1.2328766866186163 : (-0.03401896055268267, -0.01742560938609656, -0.015415302267861529, -0.740288454420207, 4.1207952214275085, 107.98561867378541)
44 = -1.2340464942825196 : (-0.03444312484088065, -0.017603258390036892, -0.015610622550061124, -0.7341072103724501, 4.115114934036736, 107.79326588806356)
45 = -1.2343102741558925 : (-0.03520022509153464, -0.017938159723464915, -0.015956072641053604, -0.7390785266763386, 4.112362034579963, 108.23148795222144)
46 = -1.234866810147868 : (-0.03537403838287974, -0.01800535037718628, -0.01603131010017496, -0.7308221398090234, 4.107097246124507, 107.9620454657341)
47 = -1.2351679092760621 : (-0.03598706696113087, -0.018254671983609992, -0.016307298642998427, -0.7249382343402715, 4.101003168572247, 107.78304931615104)
48 = -1.2357715706904866 : (-0.03701575973600991, -0.01869750748744509, -0.016773293190250352, -0.732592288412948, 4.097045300949099, 108.49053833428641)
49 = -1.2361997059870933 : (-0.03717209852155342, -0.018758485502215993, -0.016838297851174425, -0.7202362875953336, 4.089372523915529, 108.01854282170507)
50 = -1.236971282188996 : (-0.03767092379870387, -0.018950352092135747, -0.0170539679387206, -0.7104155535512385, 4.08246365623706, 107.80378300327249)
51 = -1.2371891248921867 : (-0.03867861999146589, -0.019377137679728314, -0.01749837391959477, -0.7218008262795909, 4.077435418262813, 108.48512235038464)
52 = -1.2375306059100433 : (-0.038896520560118435, -0.01946270284049261, -0.017586665161975053, -0.7038921805776892, 4.066309797061126, 107.79853285680402)
53 = -1.2379633754160444 : (-0.03951060970657978, -0.019714289922382812, -0.01784878275068907, -0.7107961768346397, 4.065587772998556, 108.26506011129231)
54 = -1.238585016497127 : (-0.03971687304177805, -0.01978994736687672, -0.0179306539402014, -0.7000136692675113, 4.059547941809343, 107.91637295088462)
55 = -1.2385124675345427 : (-0.04070401003459041, -0.020169092178874897, -0.018341005005194, -0.6949990642512212, 4.054231758919231, 108.14366007348586)
56 = -1.2392155176070163 : (-0.04131818173142632, -0.020405010840840086, -0.0185863540631594, -0.6759499582121681, 4.042017835622883, 107.55197108922127)
57 = -1.2395337963078579 : (-0.041614153631192155, -0.02053318248922818, -0.01871130028579824, -0.6925197834708661, 4.044914977128476, 108.25986699047714)
58 = -1.2402779479479369 : (-0.04172685059483518, -0.020577325204272395, -0.018756421460304727, -0.687294250788431, 4.04156131850224, 108.06509538894846)
59 = -1.240221721109648 : (-0.04189247915089833, -0.02064036195934295, -0.018821933879727682, -0.6836781529809903, 4.0396518491877345, 107.97903532190458)
60 = -1.2401802683269076 : (-0.04263632340817946, -0.02092948908381983, -0.01912006496007619, -0.6760845565610922, 4.037522164037088, 107.95506529413035)
61 = -1.2405499828816762 : (-0.04528588828840644, -0.021964123710386207, -0.02017967972270309, -0.6696157704176391, 4.025839356647181, 108.3188265313882)
62 = -1.2427209504572156 : (-0.04529586928186791, -0.021967951425031707, -0.020183991108053422, -0.6691675632657827, 4.02545575708341, 108.29071537388558)
63 = -1.2427978777012312 : (-0.04531268736895632, -0.021974378737105286, -0.020191174067994134, -0.6684584191318526, 4.024843094810378, 108.24830695196493)
64 = -1.2427236119305352 : (-0.045333319027290285, -0.021982181403083213, -0.020199860018999805, -0.6676781777388014, 4.024164659510423, 108.20507753752348)
65 = -1.242658149625584 : (-0.04537982394250271, -0.02199990689537228, -0.020219289656622598, -0.6660335928092775, 4.022825392342715, 108.12589622342675)
66 = -1.242530454933777 : (-0.045398207991623196, -0.022006699608520627, -0.020226767570348754, -0.6655281956913176, 4.022448912474788, 108.1054309783275)
67 = -1.2425523280496387 : (-0.04543157927099817, -0.022019044585853673, -0.02024028050494382, -0.6646823849682761, 4.02180604275072, 108.07367175815715)
68 = -1.242347073177542 : (-0.045507211798907356, -0.022046999240131916, -0.020270697174248325, -0.6630403423408598, 4.020487115455101, 108.02134607497155)
69 = -1.2423204588603727 : (-0.0458843508004972, -0.022188332234467287, -0.020420999671420758, -0.6575775080917906, 4.015304808984589, 107.90450973905037)
70 = -1.2425227506430705 : (-0.04656023148538967, -0.022442178519113055, -0.02068945216696431, -0.6602666973162398, 4.00986725927626, 108.25151845265582)
71 = -1.2437188633398388 : (-0.046798983236268986, -0.02253425046659166, -0.020793688276490193, -0.6512251691511246, 4.002795420078044, 107.68946671144548)
72 = -1.2433564649541557 : (-0.04715327253098815, -0.02267236295440638, -0.02093361767155557, -0.6608754179901354, 4.006018214388282, 108.33974038179466)
73 = -1.2441260846797475 : (-0.04718748673691443, -0.022685034569119474, -0.02094937705358684, -0.6591883233018989, 4.00453255744193, 108.22037549894452)
74 = -1.2442141170604468 : (-0.04719557637902359, -0.02268808408431104, -0.02095291598233483, -0.6588563644642856, 4.004306649484749, 108.20321238304446)
75 = -1.2442062719617755 : (-0.04720880098378906, -0.022693054695862858, -0.02095866040111513, -0.6583405451342051, 4.003956892629185, 108.17753782507883)
76 = -1.243875062011589 : (-0.04722271549396014, -0.022698135555182783, -0.020964598919984152, -0.6578216491815163, 4.003643759314569, 108.15295644698138)
77 = -1.243870749238259 : (-0.047240899176517644, -0.022704754777215883, -0.020972287009235292, -0.6571965767846655, 4.003268761784929, 108.12519021916496)
78 = -1.2439402127449415 : (-0.047286300468443045, -0.022721240035606004, -0.020991297754814366, -0.6557865394957486, 4.002421184379366, 108.06776842246443)
79 = -1.2439348557755627 : (-0.04746037964811349, -0.02278445209517824, -0.021062748336161168, -0.6516551083334854, 3.9999232115151653, 107.9318499075916)
80 = -1.2439378087496225 : (-0.04795894028531711, -0.022968700690554792, -0.021261881797816105, -0.6493392160679395, 3.9962099519566006, 108.05841084805127)
81 = -1.2444522715778965 : (-0.04820589341402311, -0.02305836872611479, -0.021364371731928535, -0.645237213998931, 3.992250461831286, 107.87637164813559)
82 = -1.244617185380002 : (-0.0487738092504391, -0.023271488396910595, -0.02159334192139019, -0.6480060998862468, 3.9919940470275757, 108.25004054714945)
83 = -1.245142849097484 : (-0.04890470166639948, -0.023320218082438993, -0.021654347775312915, -0.6431186539970549, 3.9869928531092294, 107.88447088166589)
84 = -1.2451730611873417 : (-0.049458276635773124, -0.023524641087670023, -0.02187821610958727, -0.6435775804751835, 3.9863451269023136, 108.2027247234898)
85 = -1.2455077918826283 : (-0.049588782522436356, -0.02357311714462687, -0.021938624492486247, -0.6392031470276748, 3.981536615663922, 107.89333706000647)
86 = -1.2455568067693108 : (-0.049889054390284536, -0.02368343556998291, -0.022061134771469666, -0.6392610980169268, 3.981051348610625, 108.04283824995039)
87 = -1.2459196920880526 : (-0.05000454137079125, -0.023724907715517753, -0.02211124688644672, -0.6372819789507131, 3.979289084649206, 107.94495983546572)
88 = -1.2458133385318997 : (-0.050519300738661614, -0.02391313344673545, -0.022324994781503654, -0.6347072043489668, 3.9759556021892837, 107.9582776110448)
89 = -1.2461875988862148 : (-0.05299803637474035, -0.02479507195789104, -0.023373880375927275, -0.613166342412159, 3.949246137783457, 107.79081003074357)
90 = -1.2477148624483703 : (-0.05334085029638737, -0.024918619839598893, -0.023513864868916816, -0.6211406077318377, 3.950894164143086, 108.23181620062974)
91 = -1.2482911864681832 : (-0.05343225137309598, -0.024954232340280158, -0.023562810307988513, -0.6175269742647989, 3.9461460496991543, 107.8567307707639)
92 = -1.2479329606912828 : (-0.053778621989628544, -0.02507146396471706, -0.023708820651044425, -0.6192952010957066, 3.9456171889473977, 108.07075138085803)
93 = -1.2485661855441423 : (-0.05392440151604775, -0.025120827235249922, -0.023779026001097117, -0.6162253048428926, 3.94204072300735, 107.79292710268474)
94 = -1.2484729751456474 : (-0.054383248374147285, -0.025273988689060906, -0.023967108305774216, -0.6183884653559394, 3.9422355922808934, 108.36112100516243)
95 = -1.249012073895017 : (-0.054402234728586525, -0.02528267899412446, -0.023978078035163226, -0.6167621933791795, 3.940641235367686, 108.22363296227684)
96 = -1.2490654179936205 : (-0.05442544236646108, -0.025291948887175664, -0.02399069745386521, -0.6155824652903649, 3.9393667823292433, 108.1206411616356)
97 = -1.2489735599715384 : (-0.05447883188195535, -0.0253112785893418, -0.0240178062920314, -0.6142764240547771, 3.937619404289977, 107.96908101997684)
98 = -1.2489076373610388 : (-0.054502619287213366, -0.02531931404035508, -0.024028492543094037, -0.6139430626822947, 3.937292168918286, 107.95145860169875)
99 = -1.248910971485021 : (-0.05453371947206704, -0.025329761984157522, -0.024042324812637433, -0.6135741768096812, 3.936913699116281, 107.93508967611736)
0 = -0.924242233339633 : (-0.05441454543230236, -0.025292072522114302, -0.024005310588219475, -0.617002191549484, 3.947506450793991, 107.96501278988752)
1 = -0.9242453994324605 : (-0.05441347423296957, -0.025292107877814208, -0.024007031739705715, -0.6171797745810895, 3.9484393665735444, 107.95133971272028)
2 = -0.9242360488136946 : (-0.05441324101976266, -0.02529211550824196, -0.02400741310121497, -0.6172193882128593, 3.9486452791638333, 107.94840505767515)
3 = -0.9242296939491337 : (-0.05441283711195057, -0.02529212870533287, -0.02400807586287082, -0.617288301151523, 3.9490028532897057, 107.94334129811348)
4 = -0.9242306957264752 : (-0.054412347378320305, -0.02529214469687957, -0.02400888493676001, -0.6173724266105175, 3.949438775841293, 107.937236689677)
5 = -0.9242130205807965 : (-0.05441186237700117, -0.025292160472894225, -0.024009693150470912, -0.6174567214034976, 3.9498728080198497, 107.93122931486435)
6 = -0.92419241577733 : (-0.054409931598445094, -0.02529221476118987, -0.024012974779970938, -0.6178020790145499, 3.951620512773909, 107.90724124083015)
7 = -0.9241962152159173 : (-0.05440831449300478, -0.025292261736715973, -0.024015802242412884, -0.6181030010804304, 3.9531162392417705, 107.88776607828008)
8 = -0.924200684049871 : (-0.054407868174493834, -0.025292271801478843, -0.024016600487715208, -0.6181877162954204, 3.9535353850833164, 107.88252094040665)
0 = -0.7633725836093499 : (-0.05440049839519708, -0.025292346857543398, -0.024015804202588194, -0.6178896339788521, 3.9529832010088044, 107.69650021453006)
1 = -0.7634709186193603 : (-0.05439964959506174, -0.025292372152354914, -0.024016507424377633, -0.6179504931169821, 3.9533219267099566, 107.68030114747752)
2 = -0.7634577277492015 : (-0.05439885760042853, -0.02529239644379717, -0.024017173467261867, -0.6180081336726676, 3.9536410867514924, 107.66522237527347)
3 = -0.76345432280931 : (-0.05439826194906865, -0.02529241504373841, -0.024017681840368524, -0.6180522770328614, 3.9538832267647837, 107.6539033718747)
4 = -0.7634453867547605 : (-0.05439749135243273, -0.025292438856982458, -0.024018346329581438, -0.6181102787599801, 3.9541986313963395, 107.63929009521235)
5 = -0.7634423851953711 : (-0.0543973368890863, -0.02529244358592935, -0.02401848131335959, -0.618122186935489, 3.9542624352984053, 107.63636652952664)
6 = -0.7634388733518241 : (-0.05439709134222603, -0.02529245093964541, -0.024018696494928347, -0.6181411928210925, 3.9543640447445023, 107.63172010354229)
7 = -0.7634394680986953 : (-0.05439682831062392, -0.02529245883771387, -0.024018927912858277, -0.61816170022583, 3.9544731792627963, 107.62674934349742)
8 = -0.7634380209846409 : (-0.05439655560288052, -0.025292466884008807, -0.024019169321294245, -0.618183177026317, 3.9545866728692216, 107.62159473155089)
9 = -0.7634346812394928 : (-0.05439623166534145, -0.02529247678280811, -0.02401945731521368, -0.6182087826364115, 3.9547218876640304, 107.61547836692563)
------- itk::simple::Euler3DTransform Euler3DTransform (0x7f8df87dcfc0) RTTI typeinfo: itk::Euler3DTransform<double> Reference Count: 3 Modified Time: 2582637 Debug: Off Object Name: Observers: none Matrix: 0.999425 0.0239787 -0.0239771 -0.0226318 0.998233 0.0549471 0.0252523 -0.0543728 0.998201 Offset: [-3.29425, 11.8293, 105.639] Center: [0.853078, -32.3853, -144.027] Translation: [-0.61795, 3.95332, 107.68] Inverse: 0.999425 -0.0226318 0.0252523 0.0239787 0.998233 -0.0543728 -0.0239771 0.0549471 0.998201 Singular: 0 AngleX: -0.0543996 AngleY: -0.0252924 AngleZ: -0.0240165 ComputeZYX: Off Optimizer stop condition: GradientDescentLineSearchOptimizerv4Template: Convergence checker passed at iteration 10. Iteration: 10 Metric value: -0.7634709186193603
In [13]:
tx = sitk.CompositeTransform([initialTransform, sitk.AffineTransform(3)])
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.9246489027264059 : (0.9974089908558552, 0.00032056228165761844, 5.297830597443564e-05, 0.00024604716550388116, 0.9982222039714761, -2.614438023337558e-05, -0.0022798356115667894, 0.014886279113618249, 0.9963704151924245, -0.03139888493098891, 0.11756924709526634, -0.41062839425054326)
1 = -0.9329251612157431 : (0.9961749786784537, 0.0004609968345551488, 5.613374670103203e-05, 0.00035762348818118856, 0.9974467421133562, 6.204854435219327e-05, -0.0022037096800858755, 0.01574145770293372, 0.9923283190620598, -0.033951733435116344, 0.11078474400363453, 0.8216753604241602)
2 = -0.9425675484883225 : (0.9958706287141689, 0.0004935470848067009, 4.203973409404129e-05, 0.0003834253051336116, 0.9972271541239995, 0.00011006747372080706, -0.0024773068663882427, 0.01737741151722013, 0.9921159311240098, -0.028980145238754352, 0.10034515001213463, 0.48552444026831476)
3 = -0.9439829114314803 : (0.9950607387816928, 0.0005841741387997406, 1.181229515171041e-05, 0.000457327414101372, 0.9966498410979091, 0.00022906224832368763, -0.0029882093296480614, 0.02026541582293507, 0.9908417279521354, -0.018718005621909874, 0.07282199758671677, 0.11589828606011865)
4 = -0.9447162295820674 : (0.9913125678083762, 0.0009898387952096911, -0.00010690574384879314, 0.0007809755631358855, 0.9940465899678642, 0.0007672792593900695, -0.0038067523461829647, 0.025127700414040267, 0.9816201419309787, 0.023578336142760052, -0.07851669428640713, 0.9097848754926282)
5 = -0.9534880135550752 : (0.9910101204131582, 0.0010244093217783494, -0.00012817374271016267, 0.0008014833536019125, 0.993801612503512, 0.0008433963450818441, -0.004151410396904882, 0.02687404814784744, 0.9818370626352215, 0.031570976340459814, -0.10428417193052229, 0.20175019122840498)
6 = -0.9564247354763359 : (0.9903912900478714, 0.0010982845231765487, -0.0001608324278799042, 0.0008494578842833573, 0.9933143472450819, 0.0009698417844007319, -0.004432321128259562, 0.027818154356902134, 0.9808336543534639, 0.04406450391953347, -0.15022204068584988, -0.1645013256975954)
7 = -0.9571498786128856 : (0.9872597398582902, 0.0014688806542792496, -0.00029016742322651777, 0.0010814149860426767, 0.9908796471023696, 0.0015060193827100632, -0.00493872000692705, 0.028336570981587123, 0.9732761836959808, 0.09412695543876856, -0.3468273803055635, 0.04978144712258992)
8 = -0.9638760405748776 : (0.9870235117160736, 0.0015063989538739542, -0.00030108477528093897, 0.0010986947924285283, 0.9906506307045011, 0.00154840762910178, -0.005134636906454853, 0.02968317778666504, 0.9733496544056116, 0.09790117281994681, -0.3590765246833331, -0.39943152225587164)
9 = -0.9651801825477209 : (0.9864179893153423, 0.00160021903801876, -0.00031890129865016337, 0.0011413713939034524, 0.990095075602002, 0.0016431511294565369, -0.005399728010554285, 0.031096572871528474, 0.9724605918455429, 0.10405636863818245, -0.3891055602793314, -0.7306461277580022)
10 = -0.9654902370242366 : (0.9844195192618598, 0.0018893863348978396, -0.0003668147664791734, 0.0012664910790028444, 0.9883297699064885, 0.001926010193029163, -0.005467280877559248, 0.031890438359315466, 0.9676383593572228, 0.12234893039120276, -0.4865820155681956, -0.3574120916418584)
11 = -0.968554622645175 : (0.9842204990969895, 0.001920381185246122, -0.00037964807595670854, 0.0012760070442258593, 0.9881227325879383, 0.001965373845071641, -0.0055747826920375014, 0.03290406096700218, 0.9677068338187856, 0.12696198241989362, -0.49945705731293377, -0.7338393809754991)
12 = -0.9695638964383053 : (0.9840333939957849, 0.0019498482780349199, -0.0003868445894868842, 0.0012840583165681589, 0.9879379422938986, 0.001996991732045236, -0.005614287644406041, 0.03329957355083311, 0.9674644733179909, 0.12952658562334848, -0.5104141166802055, -0.849301425442635)
13 = -0.969641795879245 : (0.983123023999361, 0.002091325677311051, -0.0004195578528984401, 0.0013221061554220869, 0.987049346295386, 0.0021432216381004426, -0.005736767652937153, 0.03458428200559133, 0.9659418079053395, 0.1410659671230636, -0.562011936492602, -1.141413448341475)
14 = -0.9702384547028575 : (0.981795771157444, 0.002294803217822942, -0.00045438097032265767, 0.0013669452789661872, 0.9857629652843755, 0.0023336134065050367, -0.005731492358124278, 0.034628736308783756, 0.96276883087828, 0.15281181183781709, -0.6321638815127497, -0.8043659584585736)
15 = -0.9719441939605389 : (0.9816038267004837, 0.0023235654066092186, -0.0004690366195698781, 0.0013697682434364088, 0.9855476414481925, 0.002368927991241239, -0.005817386522617649, 0.03550059125401869, 0.9628081832897116, 0.15786933681888152, -0.6440031833813359, -1.1257835406560135)
16 = -0.9723987543926742 : (0.9812400479067652, 0.0023815519435160526, -0.00048430346796425833, 0.0013753541854078463, 0.9851608406076823, 0.0024254804400817903, -0.0058813692003505166, 0.03613688187646354, 0.9623243905567966, 0.16285419964417336, -0.6641524452491658, -1.2982015171596912)
17 = -0.9724614069882767 : (0.9794597226345312, 0.002663844785670019, -0.0005441766438511555, 0.0013961980666380618, 0.9832986164557715, 0.0026891240777139227, -0.006060247329111468, 0.037134644391073404, 0.9588021516478892, 0.18151683848640365, -0.7613634219033453, -1.2617060391337651)
18 = -0.9738580124251682 : (0.9792699659880878, 0.0026928111025782825, -0.000557501117236413, 0.0013930017256472617, 0.9830742857475517, 0.002720680426417332, -0.006137044985409241, 0.03773474220240898, 0.9587347473185266, 0.18580950599932147, -0.7723759865228673, -1.4750295982573638)
19 = -0.9738481674468786 : (0.9790220483725766, 0.0027326540240932506, -0.0005688775448899378, 0.0013901350570308206, 0.9827941305484313, 0.0027574075684022124, -0.006173413794585049, 0.03798018522881549, 0.9583390851424398, 0.18927598421231548, -0.7858748696289906, -1.5234456086658152)
20 = -0.9739006146232179 : (0.9780192776633255, 0.0028951562010286662, -0.0006133610249152672, 0.001376339539199331, 0.9816585760832222, 0.0029055161138831632, -0.006303381058413558, 0.03873213650306373, 0.9566135288561112, 0.2025567595674313, -0.8406208233401542, -1.619576719048285)
21 = -0.9742352344162386 : (0.9771115617611613, 0.0030395023897628326, -0.0006616118373266329, 0.0013459081092647336, 0.9805859852043389, 0.003041561139797473, -0.006486533216488528, 0.039550801347026064, 0.9551720003488429, 0.2166035324877481, -0.8907966916012435, -1.7678419812540498)
22 = -0.974159843463866 : (0.9766842123568746, 0.0031109804978197097, -0.0006826169947255522, 0.0013260156484438562, 0.980069390284423, 0.0031046225008075413, -0.0065526228776566185, 0.039616307555210624, 0.9543057661932955, 0.22217640267893174, -0.9144937359211266, -1.6997113336408236)
23 = -0.9742780940202735 : (0.9764740988385012, 0.003145247313884944, -0.0006973903825298615, 0.001314556006998939, 0.9798070173250096, 0.0031374206288309297, -0.006630077452518119, 0.03997362062154879, 0.9540971968939854, 0.22637905171712466, -0.926374668730924, -1.8135025091658767)
24 = -0.974271048322427 : (0.9760026746472429, 0.003224836542277001, -0.0007222958315357553, 0.001287873437711217, 0.9792266609840692, 0.0032073735315957877, -0.00670550025751336, 0.040151160805792445, 0.9532263585078911, 0.2328628954548773, -0.9524754403782884, -1.7857386422724186)
25 = -0.9742472589613455 : (0.9759819683208744, 0.003228300337536401, -0.0007237126834425316, 0.0012865677835194702, 0.9792007206061344, 0.003210543173737068, -0.0067126363353349865, 0.04018067379251359, 0.9532034328022359, 0.23324813740862488, -0.9536296657522959, -1.7946727926177193)
26 = -0.9742411209884558 : (0.9759707924409664, 0.0032301756471750935, -0.0007244647505422552, 0.0012858656294538618, 0.9791867387353145, 0.003212250059532278, -0.006716346693836297, 0.04019545778135514, 0.9531903146450136, 0.23345125683575804, -0.954252408572787, -1.7989665714466592)
27 = -0.9742395550796074 : (0.9759551177834087, 0.0032328088489600587, -0.0007255118602694643, 0.0012848797110778457, 0.9791671378710454, 0.003214640272850754, -0.00672143522803477, 0.04021545217337455, 0.9531714361938286, 0.2337332303553445, -0.9551252186881729, -1.804645619573083)
28 = -0.974236646594451 : (0.9759430503868661, 0.0032348395909947087, -0.0007263101773486034, 0.0012841199351017395, 0.9791520556640035, 0.0032164769108762718, -0.0067252514044179226, 0.04023010857118237, 0.9531564339594139, 0.23394731005257138, -0.9557967715210364, -1.8086875004672494)
29 = -0.9742271071699338 : (0.9759384519338062, 0.0032356148388829656, -0.0007266121476173067, 0.0012838302206159976, 0.9791463108886325, 0.0032171750819090556, -0.006726678830274193, 0.04023549856001024, 0.953150586570292, 0.23402802176529758, -0.9560523177605782, -1.8101359483608601)
30 = -0.9742271281464893 : (0.9759343601444299, 0.0032363050140824245, -0.0007268802003734352, 0.0012835723001762716, 0.9791411996640654, 0.003217796041679825, -0.006727939831347114, 0.040240233561201676, 0.9531453435577507, 0.23409959293649946, -0.9562796646017543, -1.8113966740320697)
0 = -0.728084102876299 : (0.9764720917472657, 0.003145336966826062, -0.0006973742707983553, 0.0013144137298770244, 0.9798060312009449, 0.0031373068507865465, -0.006627554042719676, 0.03997729004767537, 0.9540978244464464, 0.22637986048006303, -0.9263263715580264, -1.8147640315495237)
1 = -0.7280829780272055 : (0.9764713629207579, 0.0031453695259817376, -0.0006973684110245811, 0.0013143620598800676, 0.9798056731622632, 0.0031372655799078446, -0.006626637644183084, 0.039978618732135096, 0.9540980495757565, 0.2263801503749914, -0.9263088550693748, -1.815220499321339)
2 = -0.7280819838207173 : (0.9764713628576913, 0.0031453695287992473, -0.0006973684105180238, 0.0013143620554098112, 0.9798056731312836, 0.0031372655763387282, -0.0066266375648820226, 0.0399786188469849, 0.9540980495951499, 0.22638015040018697, -0.9263088535545584, -1.8152205387683495)
3 = -0.7280819836710668 : (0.9764713628099275, 0.0031453695309331003, -0.0006973684101343805, 0.0013143620520242438, 0.9798056731078212, 0.003137265573635643, -0.006626637504823029, 0.03997861893396688, 0.9540980496098375, 0.2263801504192689, -0.9263088524073059, -1.8152205686437057)
4 = -0.7280819836524506 : (0.9764713627915634, 0.003145369531753521, -0.0006973684099868779, 0.0013143620507225658, 0.9798056730988004, 0.003137265572596365, -0.006626637481731636, 0.03997861896740958, 0.9540980496154845, 0.2263801504266055, -0.9263088519662119, -1.8152205801301375)
5 = -0.7280819836404158 : (0.9764713627744928, 0.003145369532516154, -0.0006973684098497648, 0.0013143620495125734, 0.979805673090415, 0.00313726557163029, -0.00662663746026672, 0.03997861899849669, 0.9540980496207339, 0.22638015043342533, -0.9263088515561871, -1.8152205908075048)
6 = -0.7280819836614505 : (0.976471362763959, 0.0031453695329867553, -0.0006973684097651558, 0.0013143620487659183, 0.9798056730852406, 0.0031372655710341503, -0.006626637447021272, 0.039978619017679747, 0.954098049623973, 0.22638015043763368, -0.9263088513031713, -1.8152205973962336)
7 = -0.7280819836506475 : (0.9764713627526341, 0.0031453695334926965, -0.0006973684096741932, 0.001314362047963193, 0.9798056730796776, 0.0031372655703932432, -0.006626637432781158, 0.039978619038303354, 0.9540980496274555, 0.22638015044215806, -0.9263088510311553, -1.8152206044797425)
8 = -0.7280819836358576 : (0.9764713627409678, 0.0031453695340138916, -0.000697368409580488, 0.0013143620471362657, 0.9798056730739468, 0.0031372655697330127, -0.006626637418111704, 0.03997861905954876, 0.9540980496310429, 0.22638015044681883, -0.926308850750938, -1.815220611776819)
9 = -0.7280819836124832 : (0.9764713627309854, 0.0031453695344598547, -0.0006973684095003087, 0.0013143620464287013, 0.9798056730690433, 0.0031372655691680835, -0.006626637405559715, 0.0399786190777275, 0.9540980496341126, 0.22638015045080684, -0.9263088505111688, -1.8152206180205974)
10 = -0.7280819835969543 : (0.9764713627304993, 0.0031453695344815717, -0.0006973684094964042, 0.001314362046394245, 0.9798056730688045, 0.003137265569140573, -0.006626637404948468, 0.03997861907861275, 0.954098049634262, 0.22638015045100104, -0.9263088504994927, -1.8152206183246518)
11 = -0.7280819836006449 : (0.9764713627302009, 0.0031453695344949052, -0.0006973684094940069, 0.0013143620463730897, 0.9798056730686578, 0.0031372655691236824, -0.006626637404573182, 0.039978619079156265, 0.9540980496343539, 0.22638015045112028, -0.926308850492324, -1.8152206185113315)
12 = -0.7280819835972294 : (0.9764713627300421, 0.0031453695345019976, -0.0006973684094927318, 0.0013143620463618368, 0.9798056730685799, 0.003137265569114698, -0.006626637404373556, 0.03997861907944538, 0.9540980496344027, 0.2263801504511837, -0.9263088504885107, -1.815220618610632)
13 = -0.7280819835957726 : (0.9764713627298257, 0.0031453695345116653, -0.0006973684094909937, 0.0013143620463464984, 0.9798056730684737, 0.0031372655691024516, -0.006626637404101456, 0.039978619079839454, 0.9540980496344692, 0.22638015045127016, -0.926308850483313, -1.8152206187459838)
14 = -0.7280819835940553 : (0.9764713627292063, 0.003145369534539336, -0.0006973684094860188, 0.001314362046302596, 0.9798056730681695, 0.0031372655690673993, -0.006626637403322641, 0.03997861908096739, 0.9540980496346597, 0.2263801504515176, -0.926308850468436, -1.8152206191333922)
15 = -0.7280819835939487 : (0.9764713627289144, 0.0031453695345523736, -0.0006973684094836748, 0.0013143620462819103, 0.9798056730680261, 0.0031372655690508834, -0.006626637402955682, 0.03997861908149885, 0.9540980496347494, 0.2263801504516342, -0.9263088504614263, -1.8152206193159297)
16 = -0.728081983595811 : (0.976471362728882, 0.003145369534553824, -0.000697368409483414, 0.0013143620462796094, 0.9798056730680101, 0.0031372655690490464, -0.006626637402914866, 0.03997861908155796, 0.9540980496347594, 0.22638015045164717, -0.9263088504606466, -1.8152206193362332)
17 = -0.7280819835942518 : (0.976471362728862, 0.0031453695345547185, -0.0006973684094832532, 0.0013143620462781895, 0.9798056730680003, 0.0031372655690479127, -0.0066266374028896785, 0.03997861908159444, 0.9540980496347655, 0.22638015045165516, -0.9263088504601654, -1.815220619348762)
18 = -0.7280819835930329 : (0.9764713627288132, 0.0031453695345569008, -0.0006973684094828608, 0.0013143620462747268, 0.9798056730679763, 0.003137265569045148, -0.00662663740282825, 0.0399786190816834, 0.9540980496347805, 0.22638015045167467, -0.926308850458992, -1.8152206193793183)
19 = -0.7280819835930106 : (0.9764713627288087, 0.0031453695345570972, -0.0006973684094828254, 0.001314362046274415, 0.9798056730679742, 0.003137265569044899, -0.00662663740282272, 0.03997861908169141, 0.9540980496347818, 0.22638015045167642, -0.9263088504588863, -1.8152206193820692)
20 = -0.7280819835930072 : (0.9764713627288061, 0.0031453695345572187, -0.0006973684094828036, 0.0013143620462742226, 0.9798056730679728, 0.0031372655690447455, -0.006626637402819307, 0.03997861908169635, 0.9540980496347827, 0.2263801504516775, -0.9263088504588212, -1.8152206193837668)
21 = -0.7280819835926092 : (0.9764713627288034, 0.0031453695345573397, -0.0006973684094827819, 0.0013143620462740305, 0.9798056730679715, 0.003137265569044592, -0.0066266374028159, 0.039978619081701285, 0.9540980496347836, 0.22638015045167859, -0.9263088504587561, -1.8152206193854614)
22 = -0.728081983592649 : (0.9764713627288024, 0.0031453695345573856, -0.0006973684094827735, 0.0013143620462739572, 0.979805673067971, 0.0031372655690445335, -0.006626637402814601, 0.039978619081703165, 0.954098049634784, 0.226380150451679, -0.9263088504587312, -1.8152206193861078)
23 = -0.728081983592649 : (0.9764713627288018, 0.0031453695345574142, -0.0006973684094827684, 0.0013143620462739121, 0.9798056730679706, 0.0031372655690444975, -0.006626637402813799, 0.039978619081704324, 0.9540980496347842, 0.22638015045167925, -0.9263088504587159, -1.8152206193865066)
24 = -0.728081983592477 : (0.9764713627288011, 0.003145369534557443, -0.0006973684094827633, 0.001314362046273867, 0.9798056730679703, 0.0031372655690444615, -0.0066266374028129986, 0.03997861908170548, 0.9540980496347844, 0.2263801504516795, -0.9263088504587006, -1.8152206193869047)
25 = -0.7280819835924721 : (0.9764713627288006, 0.0031453695345574602, -0.0006973684094827602, 0.0013143620462738393, 0.9798056730679701, 0.0031372655690444394, -0.006626637402812505, 0.0399786190817062, 0.9540980496347845, 0.22638015045167967, -0.9263088504586912, -1.8152206193871503)
26 = -0.7280819835924721 : (0.9764713627288002, 0.0031453695345574776, -0.000697368409482757, 0.0013143620462738115, 0.9798056730679698, 0.0031372655690444172, -0.006626637402812012, 0.03997861908170691, 0.9540980496347846, 0.22638015045167983, -0.9263088504586817, -1.8152206193873957)
27 = -0.7280819835924679 : (0.9764713627287998, 0.003145369534557495, -0.0006973684094827539, 0.0013143620462737838, 0.9798056730679696, 0.003137265569044395, -0.00662663740281152, 0.03997861908170763, 0.9540980496347847, 0.22638015045168, -0.9263088504586723, -1.8152206193876406)
28 = -0.7280819835924679 : (0.9764713627287995, 0.0031453695345575058, -0.0006973684094827519, 0.0013143620462737666, 0.9798056730679695, 0.0031372655690443813, -0.006626637402811216, 0.039978619081708064, 0.9540980496347848, 0.22638015045168008, -0.9263088504586665, -1.8152206193877916)
29 = -0.7280819835924679 : (0.9764713627287993, 0.0031453695345575166, -0.00069736840948275, 0.0013143620462737495, 0.9798056730679694, 0.003137265569044368, -0.0066266374028109126, 0.0399786190817085, 0.954098049634785, 0.22638015045168017, -0.9263088504586607, -1.8152206193879423)
30 = -0.7280819835920325 : (0.9764713627287991, 0.0031453695345575274, -0.000697368409482748, 0.0013143620462737324, 0.9798056730679693, 0.0031372655690443544, -0.00662663740281061, 0.03997861908170894, 0.9540980496347851, 0.22638015045168025, -0.926308850458655, -1.8152206193880929)
Out[14]:
'GradientDescentLineSearchOptimizerv4Template: Convergence checker passed at iteration 31.'
In [15]:
resample = sitk.ResampleImageFilter()
resample.SetReferenceImage(fixed_rgb)
resample.SetInterpolator(sitk.sitkBSpline3)
resample.SetTransform(outTx)
resample.AddCommand(
sitk.sitkProgressEvent,
lambda: print(f"\rProgress: {100*resample.GetProgress():03.1f}%...", end=""),
)
resample.AddCommand(sitk.sitkProgressEvent, lambda: sys.stdout.flush())
resample.AddCommand(sitk.sitkEndEvent, lambda: print("Done"))
out = resample.Execute(moving)
Progress: 0.0%...
Progress: 1.0%...
Progress: 17.8%...
Progress: 1.8%...
Progress: 4.3%...
Progress: 3.6%...
Progress: 5.5%...
Progress: 7.3%...
Progress: 9.1%...
Progress: 10.9%...
Progress: 12.7%...
Progress: 14.5%...
Progress: 16.4%...
Progress: 18.2%...
Progress: 20.0%...
Progress: 21.8%...
Progress: 23.6%...
Progress: 25.5%...
Progress: 27.3%...
Progress: 29.1%...
Progress: 30.9%...
Progress: 30.9%...
Progress: 30.9%...
Progress: 30.9%...
Progress: 30.9%...
Progress: 30.9%...
Progress: 30.9%...
Progress: 32.9%...
Progress: 43.9%...
Progress: 46.9%...
Progress: 46.9%...
Progress: 46.9%...
Progress: 46.9%...
Progress: 46.9%...
Progress: 46.9%...
Progress: 32.7%...
Progress: 34.5%...
Progress: 36.4%...
Progress: 38.2%...
Progress: 40.0%...
Progress: 41.8%...
Progress: 43.6%...
Progress: 45.5%...
Progress: 47.3%...
Progress: 49.1%...
Progress: 50.9%...
Progress: 52.7%...
Progress: 54.5%...
Progress: 56.4%...
Progress: 58.2%...
Progress: 60.0%...
Progress: 61.8%...
Progress: 61.8%...
Progress: 61.8%...
Progress: 61.8%...
Progress: 65.8%...
Progress: 71.8%...
Progress: 71.8%...
Progress: 71.8%...
Progress: 72.6%...
Progress: 61.8%...
Progress: 63.6%...
Progress: 65.5%...
Progress: 67.3%...
Progress: 69.1%...
Progress: 70.9%...
Progress: 72.7%...
Progress: 74.5%...
Progress: 76.4%...
Progress: 78.2%...
Progress: 80.0%...
Progress: 81.8%...
Progress: 83.6%...
Progress: 85.5%...
Progress: 87.3%...
Progress: 89.1%...
Progress: 90.9%...
Progress: 92.7%...
Progress: 94.5%...
Progress: 96.4%...
Progress: 98.2%...
Progress: 100.0%...
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"))