How to prevent image cropping after registration?
58 views (last 30 days)
Show older comments
I want to register a head CT (moving image) to a CT template (fixed image) for skull segmentation afterwards. The problem is my fixed image only covers the top half of the head whereas I want the output to contain the whole head.
Here is the visualization on 3D Slicer. The yellow skull is from the unregistered image, the purple is from the template, while the blue is from the registered image. The images aligned pretty nicely, with a correlation coefficient of 0.86. But I want the blue one to contain the whole head yet still be in the pink box.

I think the problem has to do with 'OutputView', and the problem might lie within this section:
% Apply the optimized transformation to the moving image
volMoving_resampled = applyTransformation(optParams, volMoving, RMoving, RFixed);
volMoving_resampled(isnan(volMoving_resampled)) = 0;
volFixed_resampled = volFixed;
Or this section, inside the 'applyTransformation' function:
% Apply transformation
tformMatrix = affinetform3d(composite_matrix);
volTransformed = imwarp(volMoving, RMoving, tformMatrix, 'OutputView', RFixed, 'FillValues', NaN);
And instead of using 'RFixed', maybe I need to create a new spatial referencing object to expand the field of view:
% Create spatial referencing objects for the fixed and moving images
pixelSpacingFixed = volFixedInfo.PixelDimensions;
pixelSpacingMoving = volMovingInfo.PixelDimensions;
RFixed = imref3d(size(volFixed), pixelSpacingFixed(1), pixelSpacingFixed(2), pixelSpacingFixed(3));
RMoving = imref3d(size(volMoving), pixelSpacingMoving(1), pixelSpacingMoving(2), pixelSpacingMoving(3));
The problem is I'm not sure how exactly to implement that in my code. Also, I am unsure if my approach is actually correct. Any help would be appreciated!
1 Comment
dpb
on 1 Jan 2026 at 14:49
I suspect you'll have to provide the image files and complete working code in order for any of the real image processing whizards to be able to help...
Answers (1)
Matt J
on 1 Jan 2026 at 19:03
Edited: Matt J
on 1 Jan 2026 at 19:33
The problem is my fixed image only covers the top half of the head whereas I want the output to contain the whole head.
But the moving image does contain the whole head? If so, then it would be,
tform = affinetform3d(composite_matrix);
ROutput = affineOutputView(size(volMoving),tform,"BoundsStyle","FollowOutput");
volMovingTransformed = imwarp(volMoving, RMoving, tform, 'OutputView', ROutput,...
'FillValues', 0);
For comparison with volFixed, you will also want to map volFixed into the same ROutput coordinate space:
tformIdentity = transltform3d([0,0,0]); %identity transform
volFixedTransformed = imwarp(volFixed, RFixed, tformIdentity, 'OutputView', ROutput,...
'FillValues', 0);
2 Comments
Matt J
on 3 Jan 2026 at 7:16
Edited: Matt J
on 5 Jan 2026 at 16:58
Did you mean, "do I need two versions of applyTransformation()"?
Even in your current version, applyTransformation does not need to be there. It is a function written by you to contain the transformation steps, not because that was necessary to do, but because that's how you chose to make your code more organized and readable.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!