Cropping image missing values after imwarp

7 次查看(过去 30 天)
I'm struggling with a theoretically simple problem, but for which I've managed to find no solution.
I've a 3D image (512x512x72) on which I have applied a rigid transformation (translation and rotation) using imwarp.
imwarp adds a given value to "pixels outside the input image" (which can be controlled via the parameter 'FillValues').
I would like to crop the output image of imwarp in a way that all those filled values are completely removed and I only keep those voxels with real values. I don't think there is a way to do this via the input parameters of imwarp.
A possible way of approaching this problem is by creating a mask (after setting 'FillValues' to NaN, for example) of the voxels with real values and then trying to come up with a way of finding the largest box that fits within that mask. This sounds simple but it is really a nightmare to try to solve this in an efficient way, so I'm not sure if that's the way to go.
Any ideas would be very appreciated :)
Thanks!

回答(2 个)

Divyank
Divyank 2023-3-16
Hello @Jorge Barrasa, I believe you're on the right track with the idea of creating a mask and finding the largest box that fits within it.
Here's a possible approach:
  1. Apply the transformation using imwarp with 'FillValues' set to NaN to create the transformed image.
  2. Create a binary mask of the transformed image, where 1 corresponds to real voxels and 0 corresponds to NaN voxels.
  3. Use the mask to find the minimum and maximum indices of non-zero voxels along each dimension (x, y, and z) using the min and max functions in MATLAB.
  4. Crop the transformed image using the minimum and maximum indices found in step 3 to obtain the largest box that fits within the mask.
I hope it helps!
  3 个评论
Image Analyst
Image Analyst 2023-3-16
Can you upload an example of your output image?
Jorge Barrasa
Jorge Barrasa 2023-3-17
The size of the image is too large to attach in the message, so I've uplodaded it to this link:
It has a variable called tmp of size 512x512x72. Imwarp has included some NaN values in the out-of-image positions. The goal is to remove all the NaNs with a minimally sized crop.
Thanks,
Jorge

请先登录,再进行评论。


Image Analyst
Image Analyst 2023-3-17
编辑:Image Analyst 2023-3-17

类别

Help CenterFile Exchange 中查找有关 Geometric Transformation and Image Registration 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by