Cropping image missing values after imwarp

5 visualizaciones (últimos 30 días)
Jorge Barrasa
Jorge Barrasa el 1 de Mzo. de 2023
Editada: Image Analyst el 17 de Mzo. de 2023
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!

Respuestas (2)

Divyank
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:
  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 comentarios
Image Analyst
Image Analyst el 16 de Mzo. de 2023
Can you upload an example of your output image?
Jorge Barrasa
Jorge Barrasa el 17 de Mzo. de 2023
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

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 17 de Mzo. de 2023
Editada: Image Analyst el 17 de Mzo. de 2023

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by