- 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
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Divyank
el 16 de Mzo. de 2023
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 comentarios
Image Analyst
el 17 de Mzo. de 2023
Editada: Image Analyst
el 17 de Mzo. de 2023
@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 comentarios
Ver también
Categorías
Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!