<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div dir="auto" style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hello all,<div><br></div><div>I am getting “out of memory” error when I run CudaForwardProjectionImageFilter.</div><div>Please refer to the attached screenshot.</div><div><br></div><div>These are the array sizes with which I get the error:</div><div><b>Projection size: (slice/row, view, column)=(1456,145,1840)</b></div><div><b>Recon size: (z, y, x)=(1264, 1356, 1356)</b></div><div><br></div><div>When I increase the voxel size to twice i.e. <b><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Recon size: (z, y, x)=(632, 678, </span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">678</span></b><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><b>)</b>, it works fine.</span></div><div><font color="#000000">Maybe I’m not being very efficient with the memory?</font></div><div><br></div><div><font color="#000000">If anyone has suggestion to make it more memory <span style="caret-color: rgb(0, 0, 0);">efficient, please let me know.</span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);">Thanks.</span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);"><br></span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);">Best,</span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);">Obaid</span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);"><br></span></font></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><b><u>Here’s what I’m doing:</u></b></span></div><div><div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">def rtk_projection(recon_arrar, proj_params, miscalib, vol_params, return_itk=False, return_RVC=True):</font></div><div><font color="#b4edff">    '''</font></div><div><font color="#b4edff">    inputs:</font></div><div><font color="#b4edff">      recon_arrar: image numpy array (ZXY format is expected)</font></div><div><font color="#b4edff">      proj_params: projection parameter dictionary</font></div><div><font color="#b4edff">      miscalib: miscalibation parameter dictionary</font></div><div><font color="#b4edff">      vol_params: image volume parameter dictionary</font></div><div><font color="#b4edff">      return_itk: True if itk image is expected, False if a numpy array is expected</font></div><div><font color="#b4edff">    output:</font></div><div><font color="#b4edff">      itk image (c,r,v format internally) or image numpy array (r,v,c format) of projection data</font></div><div><font color="#b4edff">    '''</font></div><div><font color="#b4edff">    ImageType = itk.Image[itk.F,3]; CudaImageType = itk.CudaImage[itk.F,3]</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # Convert the recon to itk format</font></div><div><font color="#b4edff">    ###########################################################################</font></div><div><font color="#b4edff">    # proj_data is in (z,x,y); rtk requires  numpy array in (x,z,y)</font></div><div><font color="#b4edff">    recon_arrar = np.transpose(recon_arrar, [1,0,2]).astype('float32') # now in (x,z,y)</font></div><div><font color="#b4edff">    recon_shape = recon_arrar.shape</font></div><div><font color="#b4edff">    recon_arrar = itk.GetImageFromArray(recon_arrar) # internally img has format (y,z,x)</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # Center the image around 0 which is the default center of rotation</font></div><div><font color="#b4edff">    recon_arrar.SetOrigin([-0.5*(recon_arrar.GetLargestPossibleRegion().GetSize()[0]-1)*recon_arrar.GetSpacing()[0],</font></div><div><font color="#b4edff">                    -0.5*(recon_arrar.GetLargestPossibleRegion().GetSize()[1]-1)*recon_arrar.GetSpacing()[1],</font></div><div><font color="#b4edff">                    -0.5*(recon_arrar.GetLargestPossibleRegion().GetSize()[2]-1)*recon_arrar.GetSpacing()[2]])</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # Graft the projections to an itk::CudaImage</font></div><div><font color="#b4edff">    ###########################################################################</font></div><div><font color="#b4edff">    vol_xy = float(vol_params['vox_xy']); vol_z = float(vol_params['vox_z'])</font></div><div><font color="#b4edff">    rtk_recon = CudaImageType.New()# img will have format crv</font></div><div><font color="#b4edff">    rtk_recon.SetPixelContainer(recon_arrar.GetPixelContainer()) # img has format crv</font></div><div><font color="#b4edff">    rtk_recon.SetLargestPossibleRegion(recon_arrar.GetLargestPossibleRegion())</font></div><div><font color="#b4edff">    rtk_recon.SetBufferedRegion(recon_arrar.GetBufferedRegion())</font></div><div><font color="#b4edff">    rtk_recon.SetRequestedRegion(recon_arrar.GetRequestedRegion())</font></div><div><font color="#b4edff">    rtk_recon.SetSpacing([vol_xy, vol_z, vol_xy]) # spacing for xzy</font></div><div><font color="#b4edff">    rtk_recon.SetOrigin([-0.5*(recon_shape[2]-1)*vol_xy, # origin for x direction</font></div><div><font color="#b4edff">                  -0.5*(recon_shape[1]-1)*vol_z, # origin for z direction</font></div><div><font color="#b4edff">                  -0.5*(recon_shape[0]-1)*vol_xy])  # origin for y direction</font></div><div><font color="#b4edff">    # print('GPU recon:', rtk_recon)</font></div><div><font color="#b4edff">    del recon_arrar</font></div><div><font color="#b4edff">    ###########################################################################</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # Defines the RTK geometry object</font></div><div><font color="#b4edff">    geometry = rtk.ThreeDCircularProjectionGeometry.New()</font></div><div><font color="#b4edff">    for i in range(len(proj_params['angles'])):</font></div><div><font color="#b4edff">        angle_deg = proj_params['angles'][i]*180/np.pi # angle in degree</font></div><div><font color="#b4edff">        geometry.AddProjection(proj_params['cone_params']['src_orig'],</font></div><div><font color="#b4edff">                               proj_params['cone_params']['src_orig']+proj_params['cone_params']['orig_det'],</font></div><div><font color="#b4edff">                               angle_deg, miscalib['delta_u'], miscalib['delta_v'])</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # define some parameters (to make code more readable)</font></div><div><font color="#b4edff">    det_pix_x = proj_params['cone_params']['pix_x'] # row direction pixel size</font></div><div><font color="#b4edff">    det_pix_y = proj_params['cone_params']['pix_y'] # channel direction pixel size</font></div><div><font color="#b4edff">    proj_shape = [int(proj_params['dims'][0]), int(proj_params['dims'][1]), int(proj_params['dims'][2])] # r,v,c</font></div><div><font color="#b4edff">    ###########################################################################</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # define a zero projection (GPU)</font></div><div><font color="#b4edff">    constantImageSource = rtk.ConstantImageSource[CudaImageType].New()</font></div><div><font color="#b4edff">    constantImageSource.SetSpacing( [det_pix_y, det_pix_x, 1.] ) # c,r,v</font></div><div><font color="#b4edff">    constantImageSource.SetSize( [proj_shape[2], proj_shape[0], proj_shape[1]] ) # c,r,v</font></div><div><font color="#b4edff">    constantImageSource.SetOrigin([ -0.5*(proj_shape[2]-1)*det_pix_y,   # origin for channel direction</font></div><div><font color="#b4edff">                                    -0.5*(proj_shape[0]-1)*det_pix_x,   # origin for row direction</font></div><div><font color="#b4edff">                                    -0.5*(proj_shape[1]-1)*1])          # origin for view direction (will be ignored anyway)</font></div><div><font color="#b4edff">    constantImageSource.SetConstant(0.)</font></div><div><font color="#b4edff">    ###########################################################################</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # forward project the recon to fill out the zero projection image</font></div><div><font color="#b4edff">    ForwardProj = rtk.CudaForwardProjectionImageFilter[CudaImageType].New()</font></div><div><font color="#b4edff">    ForwardProj.SetGeometry( geometry )</font></div><div><font color="#b4edff">    ForwardProj.SetInput(0, constantImageSource.GetOutput()) # projection image</font></div><div><font color="#b4edff">    ForwardProj.SetInput(1, cpu2gpu(rtk_recon)) # recon volume</font></div><div><font color="#b4edff">    ForwardProj.SetStepSize(float(vol_params['vox_xy'])/4) # step size along the ray (default is 1mm)</font></div><div><font color="#b4edff">    ForwardProj.Update()</font></div><div><font color="#b4edff">    ###########################################################################</font></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff">    # graft the projection to CPU / extract the array</font></div><div><font color="#b4edff">    rtk_reprojection = gpu2cpu(ForwardProj.GetOutput()) # array inside the image has c,r,v format</font></div><div><font color="#b4edff">    if return_itk:</font></div><div><font color="#b4edff">        return rtk_reprojection # array inside the image has c,r,v format</font></div><div><font color="#b4edff">    else:</font></div><div><font color="#b4edff">        rtk_reprojection = itk.GetArrayViewFromImage(rtk_reprojection) # now v,r,c format</font></div><div><font color="#b4edff">        if return_RVC:</font></div><div><font color="#b4edff">            rtk_reprojection = np.transpose(rtk_reprojection, [1,0,2]) # r,v,c format to match Astra projection</font></div><div><font color="#b4edff">        return rtk_reprojection # numpy array (r,v,c)</font></div></div></div><div><font color="#b4edff"><br></font></div><div><font color="#b4edff"><br></font></div><div><img src="cid:417B41B3-5736-41A2-AA06-75C877EED5F7" alt="Screenshot 2024-04-24 at 8.34.20 PM.png" width="602"></div><div><font color="#b4edff"><br></font></div><div><br></div></div></body></html>