In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import SimpleITK as sitk
from myshow import myshow, myshow3d
# Download data to work on
%run update_path_to_download_script
from downloaddata import fetch_data as fdata
In [2]:
img_T1 = sitk.ReadImage(fdata("nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT1.nrrd"))
img_T2 = sitk.ReadImage(fdata("nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT2.nrrd"))
img_T1_255 = sitk.Cast(sitk.RescaleIntensity(img_T1), sitk.sitkUInt8)
img_T1_255 = sitk.Cast(sitk.RescaleIntensity(img_T1), sitk.sitkUInt8)
Fetching nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT1.nrrd
Fetching nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT2.nrrd
In [3]:
sitk.Show(img_T1, title="T1")
In [4]:
idx = (106, 116, 141)
pt = img_T1.TransformIndexToPhysicalPoint(idx)
In [5]:
seg = sitk.Image(img_T1.GetSize(), sitk.sitkUInt8)
seg.CopyInformation(img_T1)
seg[idx] = 1
seg = sitk.BinaryDilate(seg, [3] * 3)
myshow3d(
sitk.LabelOverlay(img_T1_255, seg),
zslices=range(idx[2] - 3, idx[2] + 4, 3),
dpi=30,
title="Initial Seed",
)
In [6]:
stats = sitk.LabelStatisticsImageFilter()
stats.Execute(img_T1, seg)
print(stats)
itk::simple::LabelStatisticsImageFilter UseHistograms: 1 Labels: [ 1, 0 ] Debug: 0 NumberOfThreads: 16 NumberOfWorkUnits: 0 Commands: (none) ProgressMeasurement: 0 ActiveProcess: LabelStatisticsImageFilter (0x7f9b48a2a640) RTTI typeinfo: itk::LabelStatisticsImageFilter<itk::Image<float, 3u>, itk::Image<unsigned char, 3u> > Reference Count: 1 Modified Time: 4810 Debug: Off Object Name: Observers: DeleteEvent(FunctionCommand) Inputs: LabelInput: (0x7f9be98fa0e0) * Primary: (0x7f9b48861ce0) * Indexed Inputs: 0: Primary (0x7f9b48861ce0) Required Input Names: LabelInput, Primary NumberOfRequiredInputs: 1 Outputs: Primary: (0x0) Indexed Outputs: 0: Primary (0x0) NumberOfRequiredOutputs: 0 Number Of Work Units: 64 ReleaseDataFlag: Off ReleaseDataBeforeUpdateFlag: On AbortGenerateData: Off Progress: 1 Multithreader: RTTI typeinfo: itk::PoolMultiThreader Reference Count: 1 Modified Time: 4801 Debug: Off Object Name: Observers: none Number of Work Units: 64 Number of Threads: 16 Global Maximum Number Of Threads: 128 Global Default Number Of Threads: 16 Global Default Threader Type: itk::MultiThreaderBaseEnums::Threader::Pool SingleMethod: 0 SingleData: 0x0 Current Request Number: -1 NumberOfStreamDivisions: 1 RegionSplitter: ImageRegionSplitterSlowDimension (0x6000019aef00) RTTI typeinfo: itk::ImageRegionSplitterSlowDimension Reference Count: 2 Modified Time: 4803 Debug: Off Object Name: Observers: none CoordinateTolerance: 1e-06 DirectionTolerance: 1e-06 LabelStatistics: {: Count: 179 Minimum: 323.044 Maximum: 561.325 Mean: 476.567 Sum: 85305.5 SumOfSquares: 4.14695e+07 Sigma: 67.6929 Variance: 4582.33 BoundingBox: (103, 109, 113, 119, 138, 144) Histogram: Histogram (0x7f9b4fc04390) RTTI typeinfo: itk::Statistics::Histogram<double, itk::Statistics::DenseFrequencyContainer2> Reference Count: 1 Modified Time: 5012 Debug: Off Object Name: Observers: none Source: (none) Source output name: (none) Release Data: Off Data Released: False Global Release Data: Off PipelineMTime: 0 UpdateMTime: 0 RealTimeStamp: 0 seconds Length of measurement vectors in the sample: 1 Size: [256] OffsetTable: [0]: 1 [1]: 256 FrequencyContainer: DenseFrequencyContainer2 (0x600002fa4140) RTTI typeinfo: itk::Statistics::DenseFrequencyContainer2 Reference Count: 1 Modified Time: 5010 Debug: Off Object Name: Observers: none NumberOfInstances: 256 Min: [0]: -135.632 [1]: -126.774 [2]: -117.917 [3]: -109.059 [4]: -100.202 [5]: -91.3446 [6]: -82.4872 [7]: -73.6297 [8]: -64.7723 [9]: -55.9149 [10]: -47.0575 [11]: -38.2001 [12]: -29.3427 [13]: -20.4853 [14]: -11.6279 [15]: -2.77046 [16]: 6.08694 [17]: 14.9444 [18]: 23.8018 [19]: 32.6592 [20]: 41.5166 [21]: 50.374 [22]: 59.2314 [23]: 68.0888 [24]: 76.9462 [25]: 85.8036 [26]: 94.661 [27]: 103.518 [28]: 112.376 [29]: 121.233 [30]: 130.091 [31]: 138.948 [32]: 147.806 [33]: 156.663 [34]: 165.52 [35]: 174.378 [36]: 183.235 [37]: 192.093 [38]: 200.95 [39]: 209.807 [40]: 218.665 [41]: 227.522 [42]: 236.38 [43]: 245.237 [44]: 254.094 [45]: 262.952 [46]: 271.809 [47]: 280.667 [48]: 289.524 [49]: 298.382 [50]: 307.239 [51]: 316.096 [52]: 324.954 [53]: 333.811 [54]: 342.669 [55]: 351.526 [56]: 360.383 [57]: 369.241 [58]: 378.098 [59]: 386.956 [60]: 395.813 [61]: 404.67 [62]: 413.528 [63]: 422.385 [64]: 431.243 [65]: 440.1 [66]: 448.957 [67]: 457.815 [68]: 466.672 [69]: 475.53 [70]: 484.387 [71]: 493.245 [72]: 502.102 [73]: 510.959 [74]: 519.817 [75]: 528.674 [76]: 537.532 [77]: 546.389 [78]: 555.246 [79]: 564.104 [80]: 572.961 [81]: 581.819 [82]: 590.676 [83]: 599.533 [84]: 608.391 [85]: 617.248 [86]: 626.106 [87]: 634.963 [88]: 643.821 [89]: 652.678 [90]: 661.535 [91]: 670.393 [92]: 679.25 [93]: 688.108 [94]: 696.965 [95]: 705.822 [96]: 714.68 [97]: 723.537 [98]: 732.395 [99]: 741.252 [100]: 750.109 [101]: 758.967 [102]: 767.824 [103]: 776.682 [104]: 785.539 [105]: 794.396 [106]: 803.254 [107]: 812.111 [108]: 820.969 [109]: 829.826 [110]: 838.684 [111]: 847.541 [112]: 856.398 [113]: 865.256 [114]: 874.113 [115]: 882.971 [116]: 891.828 [117]: 900.685 [118]: 909.543 [119]: 918.4 [120]: 927.258 [121]: 936.115 [122]: 944.973 [123]: 953.83 [124]: 962.687 [125]: 971.545 [126]: 980.402 [127]: 989.259 [128]: 998.117 [129]: 1006.97 [130]: 1015.83 [131]: 1024.69 [132]: 1033.55 [133]: 1042.4 [134]: 1051.26 [135]: 1060.12 [136]: 1068.98 [137]: 1077.83 [138]: 1086.69 [139]: 1095.55 [140]: 1104.41 [141]: 1113.26 [142]: 1122.12 [143]: 1130.98 [144]: 1139.84 [145]: 1148.69 [146]: 1157.55 [147]: 1166.41 [148]: 1175.27 [149]: 1184.12 [150]: 1192.98 [151]: 1201.84 [152]: 1210.69 [153]: 1219.55 [154]: 1228.41 [155]: 1237.27 [156]: 1246.12 [157]: 1254.98 [158]: 1263.84 [159]: 1272.7 [160]: 1281.55 [161]: 1290.41 [162]: 1299.27 [163]: 1308.13 [164]: 1316.98 [165]: 1325.84 [166]: 1334.7 [167]: 1343.56 [168]: 1352.41 [169]: 1361.27 [170]: 1370.13 [171]: 1378.99 [172]: 1387.84 [173]: 1396.7 [174]: 1405.56 [175]: 1414.42 [176]: 1423.27 [177]: 1432.13 [178]: 1440.99 [179]: 1449.84 [180]: 1458.7 [181]: 1467.56 [182]: 1476.42 [183]: 1485.27 [184]: 1494.13 [185]: 1502.99 [186]: 1511.85 [187]: 1520.7 [188]: 1529.56 [189]: 1538.42 [190]: 1547.28 [191]: 1556.13 [192]: 1564.99 [193]: 1573.85 [194]: 1582.71 [195]: 1591.56 [196]: 1600.42 [197]: 1609.28 [198]: 1618.14 [199]: 1626.99 [200]: 1635.85 [201]: 1644.71 [202]: 1653.57 [203]: 1662.42 [204]: 1671.28 [205]: 1680.14 [206]: 1688.99 [207]: 1697.85 [208]: 1706.71 [209]: 1715.57 [210]: 1724.42 [211]: 1733.28 [212]: 1742.14 [213]: 1751 [214]: 1759.85 [215]: 1768.71 [216]: 1777.57 [217]: 1786.43 [218]: 1795.28 [219]: 1804.14 [220]: 1813 [221]: 1821.86 [222]: 1830.71 [223]: 1839.57 [224]: 1848.43 [225]: 1857.29 [226]: 1866.14 [227]: 1875 [228]: 1883.86 [229]: 1892.72 [230]: 1901.57 [231]: 1910.43 [232]: 1919.29 [233]: 1928.14 [234]: 1937 [235]: 1945.86 [236]: 1954.72 [237]: 1963.57 [238]: 1972.43 [239]: 1981.29 [240]: 1990.15 [241]: 1999 [242]: 2007.86 [243]: 2016.72 [244]: 2025.58 [245]: 2034.43 [246]: 2043.29 [247]: 2052.15 [248]: 2061.01 [249]: 2069.86 [250]: 2078.72 [251]: 2087.58 [252]: 2096.44 [253]: 2105.29 [254]: 2114.15 [255]: 2123.01 Max: [0]: -126.774 [1]: -117.917 [2]: -109.059 [3]: -100.202 [4]: -91.3446 [5]: -82.4872 [6]: -73.6297 [7]: -64.7723 [8]: -55.9149 [9]: -47.0575 [10]: -38.2001 [11]: -29.3427 [12]: -20.4853 [13]: -11.6279 [14]: -2.77046 [15]: 6.08694 [16]: 14.9444 [17]: 23.8018 [18]: 32.6592 [19]: 41.5166 [20]: 50.374 [21]: 59.2314 [22]: 68.0888 [23]: 76.9462 [24]: 85.8036 [25]: 94.661 [26]: 103.518 [27]: 112.376 [28]: 121.233 [29]: 130.091 [30]: 138.948 [31]: 147.806 [32]: 156.663 [33]: 165.52 [34]: 174.378 [35]: 183.235 [36]: 192.093 [37]: 200.95 [38]: 209.807 [39]: 218.665 [40]: 227.522 [41]: 236.38 [42]: 245.237 [43]: 254.094 [44]: 262.952 [45]: 271.809 [46]: 280.667 [47]: 289.524 [48]: 298.382 [49]: 307.239 [50]: 316.096 [51]: 324.954 [52]: 333.811 [53]: 342.669 [54]: 351.526 [55]: 360.383 [56]: 369.241 [57]: 378.098 [58]: 386.956 [59]: 395.813 [60]: 404.67 [61]: 413.528 [62]: 422.385 [63]: 431.243 [64]: 440.1 [65]: 448.957 [66]: 457.815 [67]: 466.672 [68]: 475.53 [69]: 484.387 [70]: 493.245 [71]: 502.102 [72]: 510.959 [73]: 519.817 [74]: 528.674 [75]: 537.532 [76]: 546.389 [77]: 555.246 [78]: 564.104 [79]: 572.961 [80]: 581.819 [81]: 590.676 [82]: 599.533 [83]: 608.391 [84]: 617.248 [85]: 626.106 [86]: 634.963 [87]: 643.821 [88]: 652.678 [89]: 661.535 [90]: 670.393 [91]: 679.25 [92]: 688.108 [93]: 696.965 [94]: 705.822 [95]: 714.68 [96]: 723.537 [97]: 732.395 [98]: 741.252 [99]: 750.109 [100]: 758.967 [101]: 767.824 [102]: 776.682 [103]: 785.539 [104]: 794.396 [105]: 803.254 [106]: 812.111 [107]: 820.969 [108]: 829.826 [109]: 838.684 [110]: 847.541 [111]: 856.398 [112]: 865.256 [113]: 874.113 [114]: 882.971 [115]: 891.828 [116]: 900.685 [117]: 909.543 [118]: 918.4 [119]: 927.258 [120]: 936.115 [121]: 944.973 [122]: 953.83 [123]: 962.687 [124]: 971.545 [125]: 980.402 [126]: 989.259 [127]: 998.117 [128]: 1006.97 [129]: 1015.83 [130]: 1024.69 [131]: 1033.55 [132]: 1042.4 [133]: 1051.26 [134]: 1060.12 [135]: 1068.98 [136]: 1077.83 [137]: 1086.69 [138]: 1095.55 [139]: 1104.41 [140]: 1113.26 [141]: 1122.12 [142]: 1130.98 [143]: 1139.84 [144]: 1148.69 [145]: 1157.55 [146]: 1166.41 [147]: 1175.27 [148]: 1184.12 [149]: 1192.98 [150]: 1201.84 [151]: 1210.69 [152]: 1219.55 [153]: 1228.41 [154]: 1237.27 [155]: 1246.12 [156]: 1254.98 [157]: 1263.84 [158]: 1272.7 [159]: 1281.55 [160]: 1290.41 [161]: 1299.27 [162]: 1308.13 [163]: 1316.98 [164]: 1325.84 [165]: 1334.7 [166]: 1343.56 [167]: 1352.41 [168]: 1361.27 [169]: 1370.13 [170]: 1378.99 [171]: 1387.84 [172]: 1396.7 [173]: 1405.56 [174]: 1414.42 [175]: 1423.27 [176]: 1432.13 [177]: 1440.99 [178]: 1449.84 [179]: 1458.7 [180]: 1467.56 [181]: 1476.42 [182]: 1485.27 [183]: 1494.13 [184]: 1502.99 [185]: 1511.85 [186]: 1520.7 [187]: 1529.56 [188]: 1538.42 [189]: 1547.28 [190]: 1556.13 [191]: 1564.99 [192]: 1573.85 [193]: 1582.71 [194]: 1591.56 [195]: 1600.42 [196]: 1609.28 [197]: 1618.14 [198]: 1626.99 [199]: 1635.85 [200]: 1644.71 [201]: 1653.57 [202]: 1662.42 [203]: 1671.28 [204]: 1680.14 [205]: 1688.99 [206]: 1697.85 [207]: 1706.71 [208]: 1715.57 [209]: 1724.42 [210]: 1733.28 [211]: 1742.14 [212]: 1751 [213]: 1759.85 [214]: 1768.71 [215]: 1777.57 [216]: 1786.43 [217]: 1795.28 [218]: 1804.14 [219]: 1813 [220]: 1821.86 [221]: 1830.71 [222]: 1839.57 [223]: 1848.43 [224]: 1857.29 [225]: 1866.14 [226]: 1875 [227]: 1883.86 [228]: 1892.72 [229]: 1901.57 [230]: 1910.43 [231]: 1919.29 [232]: 1928.14 [233]: 1937 [234]: 1945.86 [235]: 1954.72 [236]: 1963.57 [237]: 1972.43 [238]: 1981.29 [239]: 1990.15 [240]: 1999 [241]: 2007.86 [242]: 2016.72 [243]: 2025.58 [244]: 2034.43 [245]: 2043.29 [246]: 2052.15 [247]: 2061.01 [248]: 2069.86 [249]: 2078.72 [250]: 2087.58 [251]: 2096.44 [252]: 2105.29 [253]: 2114.15 [254]: 2123.01 [255]: 2131.87 TempMeasurementVector: [0] TempIndex: [0] ClipBinsAtEnds: On } { : Count: 19169101 Minimum: -135.632 Maximum: 2131.87 Mean: 182.056 Sum: 3.48986e+09 SumOfSquares: 1.54579e+12 Sigma: 217.934 Variance: 47495.3 BoundingBox: (0, 287, 0, 319, 0, 207) Histogram: Histogram (0x7f9b89104320) RTTI typeinfo: itk::Statistics::Histogram<double, itk::Statistics::DenseFrequencyContainer2> Reference Count: 1 Modified Time: 5064 Debug: Off Object Name: Observers: none Source: (none) Source output name: (none) Release Data: Off Data Released: False Global Release Data: Off PipelineMTime: 0 UpdateMTime: 0 RealTimeStamp: 0 seconds Length of measurement vectors in the sample: 1 Size: [256] OffsetTable: [0]: 1 [1]: 256 FrequencyContainer: DenseFrequencyContainer2 (0x600002fa8140) RTTI typeinfo: itk::Statistics::DenseFrequencyContainer2 Reference Count: 1 Modified Time: 5062 Debug: Off Object Name: Observers: none NumberOfInstances: 256 Min: [0]: -135.632 [1]: -126.774 [2]: -117.917 [3]: -109.059 [4]: -100.202 [5]: -91.3446 [6]: -82.4872 [7]: -73.6297 [8]: -64.7723 [9]: -55.9149 [10]: -47.0575 [11]: -38.2001 [12]: -29.3427 [13]: -20.4853 [14]: -11.6279 [15]: -2.77046 [16]: 6.08694 [17]: 14.9444 [18]: 23.8018 [19]: 32.6592 [20]: 41.5166 [21]: 50.374 [22]: 59.2314 [23]: 68.0888 [24]: 76.9462 [25]: 85.8036 [26]: 94.661 [27]: 103.518 [28]: 112.376 [29]: 121.233 [30]: 130.091 [31]: 138.948 [32]: 147.806 [33]: 156.663 [34]: 165.52 [35]: 174.378 [36]: 183.235 [37]: 192.093 [38]: 200.95 [39]: 209.807 [40]: 218.665 [41]: 227.522 [42]: 236.38 [43]: 245.237 [44]: 254.094 [45]: 262.952 [46]: 271.809 [47]: 280.667 [48]: 289.524 [49]: 298.382 [50]: 307.239 [51]: 316.096 [52]: 324.954 [53]: 333.811 [54]: 342.669 [55]: 351.526 [56]: 360.383 [57]: 369.241 [58]: 378.098 [59]: 386.956 [60]: 395.813 [61]: 404.67 [62]: 413.528 [63]: 422.385 [64]: 431.243 [65]: 440.1 [66]: 448.957 [67]: 457.815 [68]: 466.672 [69]: 475.53 [70]: 484.387 [71]: 493.245 [72]: 502.102 [73]: 510.959 [74]: 519.817 [75]: 528.674 [76]: 537.532 [77]: 546.389 [78]: 555.246 [79]: 564.104 [80]: 572.961 [81]: 581.819 [82]: 590.676 [83]: 599.533 [84]: 608.391 [85]: 617.248 [86]: 626.106 [87]: 634.963 [88]: 643.821 [89]: 652.678 [90]: 661.535 [91]: 670.393 [92]: 679.25 [93]: 688.108 [94]: 696.965 [95]: 705.822 [96]: 714.68 [97]: 723.537 [98]: 732.395 [99]: 741.252 [100]: 750.109 [101]: 758.967 [102]: 767.824 [103]: 776.682 [104]: 785.539 [105]: 794.396 [106]: 803.254 [107]: 812.111 [108]: 820.969 [109]: 829.826 [110]: 838.684 [111]: 847.541 [112]: 856.398 [113]: 865.256 [114]: 874.113 [115]: 882.971 [116]: 891.828 [117]: 900.685 [118]: 909.543 [119]: 918.4 [120]: 927.258 [121]: 936.115 [122]: 944.973 [123]: 953.83 [124]: 962.687 [125]: 971.545 [126]: 980.402 [127]: 989.259 [128]: 998.117 [129]: 1006.97 [130]: 1015.83 [131]: 1024.69 [132]: 1033.55 [133]: 1042.4 [134]: 1051.26 [135]: 1060.12 [136]: 1068.98 [137]: 1077.83 [138]: 1086.69 [139]: 1095.55 [140]: 1104.41 [141]: 1113.26 [142]: 1122.12 [143]: 1130.98 [144]: 1139.84 [145]: 1148.69 [146]: 1157.55 [147]: 1166.41 [148]: 1175.27 [149]: 1184.12 [150]: 1192.98 [151]: 1201.84 [152]: 1210.69 [153]: 1219.55 [154]: 1228.41 [155]: 1237.27 [156]: 1246.12 [157]: 1254.98 [158]: 1263.84 [159]: 1272.7 [160]: 1281.55 [161]: 1290.41 [162]: 1299.27 [163]: 1308.13 [164]: 1316.98 [165]: 1325.84 [166]: 1334.7 [167]: 1343.56 [168]: 1352.41 [169]: 1361.27 [170]: 1370.13 [171]: 1378.99 [172]: 1387.84 [173]: 1396.7 [174]: 1405.56 [175]: 1414.42 [176]: 1423.27 [177]: 1432.13 [178]: 1440.99 [179]: 1449.84 [180]: 1458.7 [181]: 1467.56 [182]: 1476.42 [183]: 1485.27 [184]: 1494.13 [185]: 1502.99 [186]: 1511.85 [187]: 1520.7 [188]: 1529.56 [189]: 1538.42 [190]: 1547.28 [191]: 1556.13 [192]: 1564.99 [193]: 1573.85 [194]: 1582.71 [195]: 1591.56 [196]: 1600.42 [197]: 1609.28 [198]: 1618.14 [199]: 1626.99 [200]: 1635.85 [201]: 1644.71 [202]: 1653.57 [203]: 1662.42 [204]: 1671.28 [205]: 1680.14 [206]: 1688.99 [207]: 1697.85 [208]: 1706.71 [209]: 1715.57 [210]: 1724.42 [211]: 1733.28 [212]: 1742.14 [213]: 1751 [214]: 1759.85 [215]: 1768.71 [216]: 1777.57 [217]: 1786.43 [218]: 1795.28 [219]: 1804.14 [220]: 1813 [221]: 1821.86 [222]: 1830.71 [223]: 1839.57 [224]: 1848.43 [225]: 1857.29 [226]: 1866.14 [227]: 1875 [228]: 1883.86 [229]: 1892.72 [230]: 1901.57 [231]: 1910.43 [232]: 1919.29 [233]: 1928.14 [234]: 1937 [235]: 1945.86 [236]: 1954.72 [237]: 1963.57 [238]: 1972.43 [239]: 1981.29 [240]: 1990.15 [241]: 1999 [242]: 2007.86 [243]: 2016.72 [244]: 2025.58 [245]: 2034.43 [246]: 2043.29 [247]: 2052.15 [248]: 2061.01 [249]: 2069.86 [250]: 2078.72 [251]: 2087.58 [252]: 2096.44 [253]: 2105.29 [254]: 2114.15 [255]: 2123.01 Max: [0]: -126.774 [1]: -117.917 [2]: -109.059 [3]: -100.202 [4]: -91.3446 [5]: -82.4872 [6]: -73.6297 [7]: -64.7723 [8]: -55.9149 [9]: -47.0575 [10]: -38.2001 [11]: -29.3427 [12]: -20.4853 [13]: -11.6279 [14]: -2.77046 [15]: 6.08694 [16]: 14.9444 [17]: 23.8018 [18]: 32.6592 [19]: 41.5166 [20]: 50.374 [21]: 59.2314 [22]: 68.0888 [23]: 76.9462 [24]: 85.8036 [25]: 94.661 [26]: 103.518 [27]: 112.376 [28]: 121.233 [29]: 130.091 [30]: 138.948 [31]: 147.806 [32]: 156.663 [33]: 165.52 [34]: 174.378 [35]: 183.235 [36]: 192.093 [37]: 200.95 [38]: 209.807 [39]: 218.665 [40]: 227.522 [41]: 236.38 [42]: 245.237 [43]: 254.094 [44]: 262.952 [45]: 271.809 [46]: 280.667 [47]: 289.524 [48]: 298.382 [49]: 307.239 [50]: 316.096 [51]: 324.954 [52]: 333.811 [53]: 342.669 [54]: 351.526 [55]: 360.383 [56]: 369.241 [57]: 378.098 [58]: 386.956 [59]: 395.813 [60]: 404.67 [61]: 413.528 [62]: 422.385 [63]: 431.243 [64]: 440.1 [65]: 448.957 [66]: 457.815 [67]: 466.672 [68]: 475.53 [69]: 484.387 [70]: 493.245 [71]: 502.102 [72]: 510.959 [73]: 519.817 [74]: 528.674 [75]: 537.532 [76]: 546.389 [77]: 555.246 [78]: 564.104 [79]: 572.961 [80]: 581.819 [81]: 590.676 [82]: 599.533 [83]: 608.391 [84]: 617.248 [85]: 626.106 [86]: 634.963 [87]: 643.821 [88]: 652.678 [89]: 661.535 [90]: 670.393 [91]: 679.25 [92]: 688.108 [93]: 696.965 [94]: 705.822 [95]: 714.68 [96]: 723.537 [97]: 732.395 [98]: 741.252 [99]: 750.109 [100]: 758.967 [101]: 767.824 [102]: 776.682 [103]: 785.539 [104]: 794.396 [105]: 803.254 [106]: 812.111 [107]: 820.969 [108]: 829.826 [109]: 838.684 [110]: 847.541 [111]: 856.398 [112]: 865.256 [113]: 874.113 [114]: 882.971 [115]: 891.828 [116]: 900.685 [117]: 909.543 [118]: 918.4 [119]: 927.258 [120]: 936.115 [121]: 944.973 [122]: 953.83 [123]: 962.687 [124]: 971.545 [125]: 980.402 [126]: 989.259 [127]: 998.117 [128]: 1006.97 [129]: 1015.83 [130]: 1024.69 [131]: 1033.55 [132]: 1042.4 [133]: 1051.26 [134]: 1060.12 [135]: 1068.98 [136]: 1077.83 [137]: 1086.69 [138]: 1095.55 [139]: 1104.41 [140]: 1113.26 [141]: 1122.12 [142]: 1130.98 [143]: 1139.84 [144]: 1148.69 [145]: 1157.55 [146]: 1166.41 [147]: 1175.27 [148]: 1184.12 [149]: 1192.98 [150]: 1201.84 [151]: 1210.69 [152]: 1219.55 [153]: 1228.41 [154]: 1237.27 [155]: 1246.12 [156]: 1254.98 [157]: 1263.84 [158]: 1272.7 [159]: 1281.55 [160]: 1290.41 [161]: 1299.27 [162]: 1308.13 [163]: 1316.98 [164]: 1325.84 [165]: 1334.7 [166]: 1343.56 [167]: 1352.41 [168]: 1361.27 [169]: 1370.13 [170]: 1378.99 [171]: 1387.84 [172]: 1396.7 [173]: 1405.56 [174]: 1414.42 [175]: 1423.27 [176]: 1432.13 [177]: 1440.99 [178]: 1449.84 [179]: 1458.7 [180]: 1467.56 [181]: 1476.42 [182]: 1485.27 [183]: 1494.13 [184]: 1502.99 [185]: 1511.85 [186]: 1520.7 [187]: 1529.56 [188]: 1538.42 [189]: 1547.28 [190]: 1556.13 [191]: 1564.99 [192]: 1573.85 [193]: 1582.71 [194]: 1591.56 [195]: 1600.42 [196]: 1609.28 [197]: 1618.14 [198]: 1626.99 [199]: 1635.85 [200]: 1644.71 [201]: 1653.57 [202]: 1662.42 [203]: 1671.28 [204]: 1680.14 [205]: 1688.99 [206]: 1697.85 [207]: 1706.71 [208]: 1715.57 [209]: 1724.42 [210]: 1733.28 [211]: 1742.14 [212]: 1751 [213]: 1759.85 [214]: 1768.71 [215]: 1777.57 [216]: 1786.43 [217]: 1795.28 [218]: 1804.14 [219]: 1813 [220]: 1821.86 [221]: 1830.71 [222]: 1839.57 [223]: 1848.43 [224]: 1857.29 [225]: 1866.14 [226]: 1875 [227]: 1883.86 [228]: 1892.72 [229]: 1901.57 [230]: 1910.43 [231]: 1919.29 [232]: 1928.14 [233]: 1937 [234]: 1945.86 [235]: 1954.72 [236]: 1963.57 [237]: 1972.43 [238]: 1981.29 [239]: 1990.15 [240]: 1999 [241]: 2007.86 [242]: 2016.72 [243]: 2025.58 [244]: 2034.43 [245]: 2043.29 [246]: 2052.15 [247]: 2061.01 [248]: 2069.86 [249]: 2078.72 [250]: 2087.58 [251]: 2096.44 [252]: 2105.29 [253]: 2114.15 [254]: 2123.01 [255]: 2131.87 TempMeasurementVector: [0] TempIndex: [0] ClipBinsAtEnds: On } ValidLabelValues: (, ) UseHistograms: On NumBins: [256] LowerBound: -135.632 UpperBound: 2131.87
In [7]:
factor = 1.5
lower_threshold = stats.GetMean(1) - factor * stats.GetSigma(1)
upper_threshold = stats.GetMean(1) + factor * stats.GetSigma(1)
In [8]:
init_ls = sitk.SignedMaurerDistanceMap(seg, insideIsPositive=True, useImageSpacing=True)
In [9]:
lsFilter = sitk.ThresholdSegmentationLevelSetImageFilter()
lsFilter.SetLowerThreshold(lower_threshold)
lsFilter.SetUpperThreshold(upper_threshold)
lsFilter.SetMaximumRMSError(0.02)
lsFilter.SetNumberOfIterations(100)
lsFilter.SetCurvatureScaling(1)
lsFilter.SetPropagationScaling(1)
lsFilter.ReverseExpansionDirectionOn()
ls = lsFilter.Execute(init_ls, sitk.Cast(img_T1, sitk.sitkFloat32))
print(lsFilter)
itk::simple::ThresholdSegmentationLevelSetImageFilter LowerThreshold: 375.028 UpperThreshold: 578.107 MaximumRMSError: 0.02 PropagationScaling: 1 CurvatureScaling: 1 NumberOfIterations: 100 ReverseExpansionDirection: 1 ElapsedIterations: 100 RMSChange: 0.0691501 Debug: 0 NumberOfThreads: 16 NumberOfWorkUnits: 0 Commands: (none) ProgressMeasurement: 1 ActiveProcess: (none)
In [10]:
zslice_offset = 4
t = "LevelSet after " + str(lsFilter.GetNumberOfIterations()) + " iterations"
myshow3d(
sitk.LabelOverlay(img_T1_255, ls > 0),
zslices=range(idx[2] - zslice_offset, idx[2] + zslice_offset + 1, zslice_offset),
dpi=20,
title=t,
)
In [11]:
lsFilter.SetNumberOfIterations(25)
img_T1f = sitk.Cast(img_T1, sitk.sitkFloat32)
ls = init_ls
niter = 0
for i in range(0, 10):
ls = lsFilter.Execute(ls, img_T1f)
niter += lsFilter.GetNumberOfIterations()
t = (
"LevelSet after "
+ str(niter)
+ " iterations and RMS "
+ str(lsFilter.GetRMSChange())
)
fig = myshow3d(
sitk.LabelOverlay(img_T1_255, ls > 0),
zslices=range(
idx[2] - zslice_offset, idx[2] + zslice_offset + 1, zslice_offset
),
dpi=20,
title=t,
)