介紹如何在 Python 中使用 ITK 的 SimpleFilterWatcher
輸出指定 filter 產生的管線事件(pieline events)詳細資訊。
在開發 ITK 應用程式時,如果需要觀察管線內部各個 filter 的運作狀況,可以在程式中加入
SimpleFilterWatcher
,把指定 filter 的所產生的所有管線事件輸出至標準輸出(standard output)。
import itk # 影像維度 Dimension = 3 # 輸入影像類型 InputPixelType = itk.US InputImageType = itk.Image[InputPixelType, Dimension] # 讀取 MHA 影像檔案 inputImageFilename = "input.mha" # 建立影像 Reader reader = itk.ImageFileReader[InputImageType].New(FileName=inputImageFilename) # 建立 ThresholdImageFilter thresholdFilter = itk.ThresholdImageFilter[InputImageType].New() thresholdFilter.SetInput(reader.GetOutput()) thresholdFilter.ThresholdBelow(100) thresholdFilter.SetOutsideValue(0) # 輸出 Filter 管線事件資訊 watcher = itk.SimpleFilterWatcher(thresholdFilter, "Threshold") # 實際執行 thresholdFilter.Update()
-------- Start ThresholdImageFilter "Threshold" ThresholdImageFilter (0x358caa0) RTTI typeinfo: itk::ThresholdImageFilter<itk::Image<unsigned short, 3u> > Reference Count: 3 Modified Time: 16 Debug: Off Object Name: Observers: StartEvent(SimpleMemberCommand) EndEvent(SimpleMemberCommand) ProgressEvent(SimpleMemberCommand) IterationEvent(SimpleMemberCommand) AbortEvent(SimpleMemberCommand) Inputs: Primary: (0x35ffa10) * Indexed Inputs: 0: Primary (0x35ffa10) Required Input Names: Primary NumberOfRequiredInputs: 1 Outputs: Primary: (0x41b7e60) Indexed Outputs: 0: Primary (0x41b7e60) NumberOfRequiredOutputs: 1 Number Of Work Units: 128 ReleaseDataFlag: Off ReleaseDataBeforeUpdateFlag: Off AbortGenerateData: Off Progress: 0 Multithreader: RTTI typeinfo: itk::PoolMultiThreader Reference Count: 1 Modified Time: 2 Debug: Off Object Name: Observers: none Number of Work Units: 128 Number of Threads: 48 Global Maximum Number Of Threads: 128 Global Default Number Of Threads: 48 Global Default Threader Type: itk::MultiThreaderBaseEnums::Threader::Pool SingleMethod: 0 SingleData: 0 DynamicMultiThreading: On CoordinateTolerance: 1e-06 DirectionTolerance: 1e-06 InPlace: Off The input and output to this filter are the same type. The filter can be run in place. OutsideValue: 0 Lower: 100 Upper: 65535 Progress | 0.00943396 Filter took 0.0180871 seconds. -------- End ThresholdImageFilter "Threshold" ThresholdImageFilter (0x358caa0) RTTI typeinfo: itk::ThresholdImageFilter<itk::Image<unsigned short, 3u> > Reference Count: 3 Modified Time: 16 Debug: Off Object Name: Observers: StartEvent(SimpleMemberCommand) EndEvent(SimpleMemberCommand) ProgressEvent(SimpleMemberCommand) IterationEvent(SimpleMemberCommand) AbortEvent(SimpleMemberCommand) Inputs: Primary: (0x35ffa10) * Indexed Inputs: 0: Primary (0x35ffa10) Required Input Names: Primary NumberOfRequiredInputs: 1 Outputs: Primary: (0x41b7e60) Indexed Outputs: 0: Primary (0x41b7e60) NumberOfRequiredOutputs: 1 Number Of Work Units: 128 ReleaseDataFlag: Off ReleaseDataBeforeUpdateFlag: Off AbortGenerateData: Off Progress: 1 Multithreader: RTTI typeinfo: itk::PoolMultiThreader Reference Count: 1 Modified Time: 2 Debug: Off Object Name: Observers: none Number of Work Units: 128 Number of Threads: 48 Global Maximum Number Of Threads: 128 Global Default Number Of Threads: 48 Global Default Threader Type: itk::MultiThreaderBaseEnums::Threader::Pool SingleMethod: 0 SingleData: 0 DynamicMultiThreading: On CoordinateTolerance: 1e-06 DirectionTolerance: 1e-06 InPlace: Off The input and output to this filter are the same type. The filter can be run in place. OutsideValue: 0 Lower: 100 Upper: 65535
參考資料:ITKExamples