Cropping image missing values after imwarp

조회 수: 13 (최근 30일)
Jorge Barrasa
Jorge Barrasa 2023년 3월 1일
편집: Image Analyst 2023년 3월 17일
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