When setting a reference image on a filter or a source in ITK, the intention is that the output properties such as size, spacing, direction will be obtained from the reference image — is this correct?
Somehow, when playing with GridImageSource in ITK Python, the use of reference image crashes the script on calling the Update method. Here’s the code:
Process finished with exit code -1073740940 (0xC0000374)
While having a closer look at the API, it became apparent that despite the use of reference image, grid_source.SetSize([...,...]) has to be called — and the things run as expected.
However, there’s also a helper method grid_source.SetOutputParametersFromImage(img), which does the trick, setting spacing, direction and size.
My question is this — what’s the preferred/intended use of those two methods, SetReferenceImage and SetOutputParametersFromImage, given that they are there to do the same thing, unless I’m missing something?
The key difference is that SetReferenceImage sets an optional pipeline input to the filter, while SetOutputParametersFromImage immediately set the SetOrigin, SetSize, etc. methods.
The crash is likely related to how the img is connected to a filter that generated it or modified since.
In general I would read the ITK Software Guide: https://itk.org/ItkSoftwareGuide.pdf to get a understanding of the pipeline and the advantages of using it.
For this particular case, I can’t think of a reason to prefer the pipelined reference image over the SetOutputParametersFromImage method.
I did read the ITK Software Guide (and, in fact contributed and edited a bit a few years back), but upon review there’s not much about the use of reference images in the pipeline, except for metadata source in some instances in Book 2; Book 1 is even less helpful with this matter.
And, that’s why I’m trying to dig a bit deeper for better insights here.
I thought your question was more in general about pipelines and when they could be used advantageously for streaming, out of core processing, GUI driven execution or select ROI updates. For sources I can’t think how those may be useful for these filters.
As I recall both of these methods exists in the base class because there were inconsistencies between different ways of setting these parameters is different “ImageSources” so a common base class was added with both methods. The SetReferenceImage method is in some other filters like ResampleImageFilter.