I want to downsample my dataset in the Z direction by a factor of 3. More precisely I want to average 3 slices together.
I realized (I think) that 3dresample would not work to achieve that averaging whether I use NN or Li. I am not sure what Blocky exactly do.
However, it seems to me that I could do it with 3dLocStat:
3dLocalstat -nbhd 'RECT(0,0,-1)' -mask mask.nii.gz -stat mean -reduce_grid 1 1 3 -prefix data_lowres.nii.gz data_hires.nii.gz
What do you think? Is that correct? Is that possible to do that using 3dresample?
It looks like it is possible to do the actual downsampling after averaging all within 3dLocstat by using the option -reduce_grid 1 1 3.
I think it worked as the resulting dim is correct.
original dim:
R-to-L extent: -79.101 [R] -to- 87.028 [L] -step- 1.613 mm [104 voxels]
I am not sure if that is working quite the way you would want, in that the grid reduction will be an interpolated one (in the z-direction). But to get an accurate mean, run 3dLocalstat first followed by the 3dresample version that I suggested (that is a fairly new method, many years newer than 3dLocalstat - we might want to consider updating the method in 3dLocalstat).
You could then compare the results.
How precisely do you want that mean computed? Maybe you won't mind the extra resampling blur...
So, I compared both methods and they gives me exactly the same results, bit to bit.
I also checked with the cursor a few voxels and it is the average of 3 voxels in the z direction.
Just to be clear, "3dresample -dxyz ..." is not quit what I recommend. Indeed, that ought to give the same result. Using "3dresample -downsample 3" might be more precisely what you want. But if you are happy with this, it is great.
The
National Institute of Mental Health (NIMH) is part of the National Institutes of
Health (NIH), a component of the U.S. Department of Health and Human
Services.