Hi, I am trying to save binary labelmaps that I have transformed with specific transform files. The problem is that I have clicked the harden transform button, but when I go to save the files, they do not save in the correct orientation, but rather the initial orientation. Is there an easy way to save the new matrices corresponding to the transformed labelmaps?
In addition, is there a way to save a transformed segmentation? Again, I have tried hardening the renasform and saving the seg.nrrd file, but the outcome is the original segmentation orientation, and not the transformed orientation.
Hardening linear transforms on volumes don’t require changing voxel values, you’ll only see result of hardening as an update in axis direction information. This operation is fast, reversible, and no information is lost.
To deal with software that don’t work in physical space (ignores axis direction information, etc) you can export the segmentation into a labelmap volume. You can specify any volume as a reference volume and voxels will be resampled into that voxel grid. See https://www.slicer.org/wiki/Documentation/Nightly/Modules/Segmentations for details.
How would you go about saving the volume that is transformed then?
To resample volumes, use Resample Scalar Volume and similar resample modules.
Here is a summary of the great answers of @lassoan :
What is the effect of Hardening linear transforms ?
How to deal with software that don’t work in physical space ?
For segmentations
For Volumes
Hi there, don’t know have you resolved your dilemma or not. I faced the same trouble when trying to save transformed model. It turned out that we need to select the files ( right click) in the transformed object box before hitting the hardening button. After clicking hardening, the files from the transformed object box will move back to the transformable box. Then you can save the transformed files.
Hope it helps^^
how to do harden transform using python script?
regards,
Saima
Once you have a transformable node that has an associated transform (e.g. like this), you can call the HardenTransform()
method on that node: transformableNode.HardenTransform()
.
This does not work for me.
Has anyone solved this issue? I want to transform a volume and create another one with the same size. So then I can export it in dcm format and open it with pydicom or export the slices in .npy format. How can I do it?
Now I’m:
- Creating the transformation matrix and applying it with the Transformation module.
- In data module right click and harden transform
- Export as DICOM
I don’t think there is an issue. There are many ways to apply a transform to a volume and you need to use the tools in Slicer that correspond to what you would like to achieve.
I want to transform a volume and create another one with the same size.
Do you want to resample the transformed volume into the same geometry (origin, spacing, axis direction, and extents) as the original volume? Then you can use “Resample scalar/vector/DWI volume” module and set the original volume as “Reference volume” and set the transform as “Transform node”.
How do you deal with cases when the transformed volume gets cropped? Because this procedure takes the image size from the input node.
You can create a larger target volume using the CropVolume module.
It would be an interesting feature to consider automatically creating a target volume that includes all of the transformed range of the volume, but I don’t think we have that.
Yes, i tried that. it turns into a multi-step process, where you do one resample, notice that it is cut, use the CropVolume to expand in the regions where there is cut. Go back to resample, set the new volume as the reference volume, and repeat the procedure until FOV is no longer cut.
While it works, it is a quite tedious. Would be nice to automatically figure out what the resultant image size need to be.
If you apply the transform to the volume you can look at it in the slice views and adjust the ROI to fit it, so it shouldn’t be too hard. But I agree, the process could be automated.
It would be great, if this is actually a feature of CropVolume. A third option, which will create a resampled output image using the ROI.
Resample DWI has so many options that is intimidating to begin with.
When you harden a transform on a volume, Slicer performs this extent computation automatically. It takes into account all translation/rotarion/warping of the volume and does not compute the new extent based on only the 8 corners but many points on the bounding box of the volume.
This automatic extent computation is used by Crop volume module, too, when the “Fit to volume” button is pressed. However, when you transform and resample you most often want to cut into the volume (to cut off the wavy sides of the warped volume). Maybe what is needed would be to have an option to reset the ROI size without changing its orientation. Or maybe to have a minimal ROI option (where the ROI is the largest box that fits within the warped volume).
Thanks, that’s what I wanted.
I have another question. I’ve noticed that when I apply a transformation to a volume via the Transforms module, Slicer selects automatically a “Reformat” view in the red slice. How can I use this “Reformat” view as the axial view and save the volume accordingly?
Many thanks