Hi, I am sorry for troubling you so many times.
I am trying to resize my image from (530,530,604) ->(512,512,604), then i use ResampleImageFilter, ScaleTransform and BSplineInterpolateImageFunction to do it. The converted image is full of zeros,why?
code snippet:
Hi, @dzenanz
I have changed the integer division into float division, but it has little effect.
I solved this problem by annotating resamplefilter->SetOutputParametersFromImage(img) and everything has to do with spacing ,origin and direction. I do not know the reason why it works.
In your code sample, I don’t see resamplefilter->SetInput(), so I can’t tell what is it that you are resampling. If you used img both as input, and output reference, that would be unexpected. I don’t know why it wouldn’t produce some result, though.
the img is the input image. I don`t know what does it mean?
output reference
If you point to resamplefilter->SetOutputParametersFromImage(img);, I set spacing and shape underneath this code. Don`t be worry.
There is still a problem about resample, sometimes this function does not work(I mean the image full of zero ,but shape has changed), no matter scale up or scale dowm.
If you just want to change resolution of the image, you don’t need the scale transform - implicit identity transform will do. Your image probably has non-zero origin, which makes the resampling miss the object. Here is what I tried:
When scale transform is used, the object gets distorted (in my case, significantly squished). When it is commented out, the resampling works as expected.
Scale transform works with BSpline. But for resampling the image, you don’t need the scale transform. The physical size of the objects in the image remain the same, only the image sampling grid changes (size and spacing).
If you want to change the size of the objects in the image, then you use scaling transform. For example, you want to register a head of a child to a head of an adult - you would need scaling (together with translation and rotation).