Once I have a registration, what is the best way to extract the deformation field (a.k.a. displacement field) with ITK Python? The idea is to avoid reprocessing and have shorter code.
is this also the case once the scaling, origin and direction are set for the image (as shown in Sec. 4.14 Defining Origin and Spacing of the Software Guide)?
is a composite transform (permalink) a better alternative? (As I am looking for a Python ITK solution, I would translate the SimpleITK syntax).
is there a way to get the displacement (deformation) field from the registration or transform directly? (as in: a method of the Transform class) [Edit]. itk.TransformToDisplacementFieldFilter tells me that AttributeError: module 'itk' has no attribute 'TransformToDisplacementFieldFilter'
is there a full example which shows how to extract the displacements from a rigid registration?
TransformToDisplacementFieldFilter is wrapped for Python. If you compiled ITK from source, make sure that ITK_WRAP_vector_float is enabled and ITK_WRAP_VECTOR_COMPONENTS contains 3. A Python example which touches a deformation field might be useful from syntax perspective.
Hi there, Dženan. Thank you. My CMakeCache.txt shows:
//Number of vector components available separated by semicolons
// (;)
ITK_WRAP_VECTOR_COMPONENTS:STRING=2;3;4
...
//Wrap vector float type
ITK_WRAP_vector_float:BOOL=ON
and my compilation instructions include
-DITK_WRAP_IMAGE_DIMS:STRING="2;3;4"
Do you think that there would be a difference if I recompile like this?:
Thank you again, Dženan. As I am looking into my makepkg.conf (makepkg is the building tool of Arch-based systems), I see that there is an option to disable and clear static libraries. I wonder if that has to do with it. I will disable the option, compile and report back. Thanks.
In the example which is linked above, the deformation field is provided as an input (deformationField = fieldReader.GetOutput()). I already tried to look into the documentation mentioned by @matt.mccormickover here, and with help(displ_filt). Right now, I am unsure of how to get the deformation field from the registration or movingInitialTransform. Any tips? Thank you in advance.
RuntimeError: /pkg/insight-toolkit/src/insight-toolkit/Modules/Core/Common/src/itkProcessObject.cxx:1339:
ITK ERROR: TransformToDisplacementFieldFilter(0x55578b3cac50): Input Transform is required but not set.
RuntimeError: /pkg/insight-toolkit/src/insight-toolkit/Modules/IO/ImageBase/include/itkImageFileWriter.hxx:245:
ITK ERROR: ImageFileWriter(0x555788553d50): Largest possible region does not fully contain requested paste IO regionPaste IO region: ImageIORegion (0x7ffd35280600)
Dimension: 3
Index: 0 0 0
Size: 0 0 0
Largest possible region: ImageRegion (0x7ffd35280760)
Dimension: 3
Index: [0, 0, 0]
Size: [0, 0, 0]
I tried other approaches, but I’m sure that expanding on my mistakes is of no use . How do I save the results? (is what I did to get them the right way?). Thank you again .
Oh, you need to specify the size etc of the desired displacement field. Use TransformToDisplacementFieldFilter.SetReferenceImage() plus UseReferenceImageOn or SetOutputOrigin, SetOutputSpacing etc. See docs for SetReferenceImage.
This method can be used to specify an image from which to copy the [output information (SetOutputSpacing, Origin, and Direction)]. UseReferenceImageOn must be set
The (VTK) output shows up in ParaView as a block with the size of my fixed_image, completely full of little glyphs in the same direction. This makes me think that I will have to do this with a moving window (an area smaller than the full image) whose position I will move iteratively to get the displacements at each point, correct? This is possibly what @matt.mccormick was trying to say:
, I was expecting to get zero deformation in the gray areas. With the results from TransformToDisplacementFieldFilter (by means of itk.imwrite(displ_field_out, displ_field_vtk)), I get a uniform field of vectors
. I am assuming that these vectors are the values of deformation.
Since the field is uniform, what I am assuming is that the overall displacement of the smile is applied in the whole region. That is, having used fixed_image (which is the full original image) results in the overall value being applied everywhere.
Therefore, I would think that I need to calculate the deformation at each point… but isn’t that the goal of TransformToDisplacementFieldFilter? (to get the deformation at each point?). Thus, I must be doing something wrong.
Displacement field provides translation vector at each point. But if you construct it by computing rigid transform for each of those points, you get a rather uniform DF. So if you have a rigid transform, it is best to keep it in some specialized format (a few numbers specifying translation, rotation and center of rotation).
What you might be looking for is deformable registration. But even with deformable registration, most algorithms would produce movement in the gray areas between the eyes. Why? Because if they didn’t, it would imply huge deformations around the eyes and mouth and no deformation for the rest of the face. Put another way: if your head is translated, each point of your forehead is translated too, not just the eyes.