3dNwarpApply malloc (out of memory)

Hi,

I am creating a pipeline to register a CT segmentation in template space to CTs of stroke patients to gather volumetric information (total GM and WM volumes). So far, I perform the following preprocessing on the patient CT (windowing, blurring, skullstrip):

3dcalc -a ROUTINE_HEAD_2_Tilt_1.nii’<0…200>’ -expr a -prefix CT_noskull.nii -overwrite
3dBlurToFWHM -input CT_noskull.nii -prefix CT_smoothed.nii -FWHM 3
3dSkullStrip -prefix CT_ns.nii -input CT_smoothed.nii -shrink_fac 0.01

Followed by this call to 3dQwarp to align the template to subject space:
3dQwarp -prefix template2anat.nii -source template.nii.gz -base CT_ns.nii -blur 0 3 -allineate -allopt ‘-twopass -cmass’ -emask ich_classification_mask.nii.gz

There is a corresponding GM segmentation that I am trying to align to subject space using:
3dNwarpApply -prefix gm2anat.nii -source gm.nii -nwarp ‘template2anat_WARP.nii template2anat_Allin.aff12.1D’ -verb

However, I receive the following error:
++ 3dNwarpApply: AFNI version=AFNI_20.3.02 (Nov 12 2020) [64-bit]
++ Authored by: Zhark the Warped
++ opened source dataset ‘gm.nii’
++ Processing -nwarp ++ Enter IW3D_read_nwarp_catlist( template2anat_WARP.nii template2anat_Allin.aff12.1D )

  • Open dataset warp template2anat_WARP.nii
  • max displacments = 163.484 85.9065 171.832
  • Open matrix file template2anat_Allin.aff12.1D
  • max shifts = 126.625 59.573 147.323
  • — Totalized max displacments = 290.109 145.479 319.155
    ++ IW3D_set_geometry_nwarp_catlist: padding = 743
  • results: master_geomstring = MATRIX(0.429688,0,0,-110,0,-0.429688,0,81.83273,0,0,5.0002,-129.112):512,738,46 actual_geomstring = MATRIX(0.429688,0,0,-429.2582,0,-0.429688,0,401.0909,0,0,5.0002,-3844.26):1998,2224,1532
  • – warp #0 geometry = MATRIX(0.429688,0,0,-110,0,-0.429688,0,81.83273,0,0,5.0002,-129.112):512,738,46
  • regridding warp #0 to geometry = MATRIX(0.429688,0,0,-429.2582,0,-0.429688,0,401.0909,0,0,5.0002,-3844.26):1998,2224,1532

mat44 nwarp_catlist actual_cmat:

  0.429688      0.000000      0.000000    -429.258209
  0.000000     -0.429688      0.000000     401.090912
  0.000000      0.000000      5.000200   -3844.260010

mat44 nwarp_catlist actual_imat:

  2.327270     -0.000000     -0.000000     998.999756
 -0.000000     -2.327270     -0.000000     933.446838
 -0.000000     -0.000000      0.199992     768.821289

+++++ initial structure of Nwarp_catlist: Nwarp ; Matrix[1] ;
++ – IW3D_reduce_nwarp_catlist – start loop

  • looking at nwc[0]
  • #0 and #1 are neighbors
  • – loop reduction operation count = 0
    ++ – IW3D_reduce_nwarp_catlist – start loop
  • looking at nwc[0]
  • #0 and #1 are neighbors
  • IW3D_reduce_nwarp_catlist: warp-Matrix[1] ii=0 jj=1
    ** ERROR: malloc failure for image space: 1460282880 bytes
    ** ERROR: nx=1998 ny=2224 nz=1532 npix=-1782412928
    in file: mri_new.c at line 140
    THD_nwarp_regrid
    IW3D_set_geometry_nwarp_catlist
    IW3D_read_nwarp_catlist
    3dNwarpApply

I have plenty of free memory (107 GB) so imagine there is another problem that I am not seeing. I have tried on both Ubuntu 18.04 and Ubuntu 20.04 (both on WSL) and a Centos 7 VM, and receive the same error. Any guidance is greatly appreciated!

Thanks,
Brady