ITK::image在使用时的注意事项
1. ITK::Image的三种Region
ITK::Image在使用的时候有三个相关的Region需要注意:LargestPossibleRegion, RequestedRegion, BufferRegion。
在ITK的官方定义中,三种Region的定义如下:
LargestPossibleRegion defines the size and starting index of the image dataset. The entire image dataset, however, may not be resident in memory.
BufferRegion is the region of the image that is resident in memory. The Buffer is a contiguous block of memory.
RequestedRegion is used by the pipeline execution model to define what a filter is requested to produce.
2. Invalid RequestedRegion Error
ITK::Image VerifyRequestedRegion()
在PipeLine中对图像进行处理时,最经常使用的就是RequestedRegion。
在对图像进行处理时,最常见的Exception就是”Invalid RequestedRegion Error”,造成这种情况的主要原因就是RequestedRegion 的索引范围超过了 LargestPossibleRegion。
要避免这种问题,可以在使用RequestedRegion之前,首先对itk::image使用VerifyRequestedRegion进行检验。
ITK::ImageToImageFilter UpdateLargestPossibleRegion()
在使用itk::ImageToImgaeFilter对图像进行处理时,常见的问题就是当Filter中Image的Size发生变化时,RequestedRegion并没有发生变化。在这种情况下,对Filter进行Update()获得图像输出时,就会出现Invalid RequestedRegion Error的错误。
避免这种错误的方法就是将Filter的Update()换成UpdateLargestPossibleRegion()。这样在运行PipeLine的时候,可以自动更新Filter中的ImageSize。
值得注意的是,在ITK中的itk::ImageToVTKImageFitler中,却不需要上述的转换,直接使用Update()即可。
3. ITK::Image 初始化时的操作
此外,在对itk::Image进行初始化的时候(调用Intialize())时,只是对image allocated memory进行了清理,但是image的Size等都没有进行更新。这个时候,要调用UpdateOutputInformation()来对image中的其他参数进行更新,包括size, origin, spacing等等。
参考文档: