- Apply the transformation using imwarp with 'FillValues' set to NaN to create the transformed image.
- Create a binary mask of the transformed image, where 1 corresponds to real voxels and 0 corresponds to NaN voxels.
- 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.
- Crop the transformed image using the minimum and maximum indices found in step 3 to obtain the largest box that fits within the mask.
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!
0 个评论
回答(2 个)
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:
I hope it helps!
3 个评论
Image Analyst
2023-3-17
编辑:Image Analyst
2023-3-17
@Jorge Barrasa try searching for "largest Interior box"
Evidently it is a very challenging problem. A few years ago it was solved and the algorithm published here:
Note that the corners of the box don't always fall on the perimeter.
If we're lucky, @John D'E will publish it as a companion to his File Exchange entry that finds the smallest bounding box:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!