[ITK] SimpleITK optimize memory management for 4d image registration

Bradley Lowekamp blowekamp at mail.nih.gov
Fri Mar 27 10:05:15 EDT 2015


Hello,

It's a bit hard to follow the code with how you have formatted. How big are your images?

1) Consider using LabelStatisticImageFilter to compute the bounding box.

2) You have a lot of Slicer, VTK, and SimpleITK code going on here. Frequently with Python code the expense of keeping images on the can build up, so sometimes you need to explicitly "del" them when finished. I don't see too many extras going on here however.

3) I think you need to narrow down the memory problem. You are pushing a lot of images to slicer and not removing them. I am not sure if this is really an SimpleITK usage issue or a Slicer MRML usage issue.

Hope that helps,
Brad

On Mar 27, 2015, at 9:52 AM, Cyril Jaudet <drcjaudet at gmail.com> wrote:

> Hello itk community,
> 
> i use a python code to extract, crop, register and export 4d image. This code interact with 3Dslicer.
> Do you know how optimize the memory management because it use more then 15Gb of memory when running ? 
> 
> Thank you,
>  
> 
> Cyril Jaudet
> Medical physicist, phd
> 
> 
> cyril.jaudet at uzbrussel.be
> 
> 
> 
> 
> 
> 
> 
> def CropAndRegister(multi,reference,label):
>     multiNode=slicer.util.getNode(multi)
>     refNode=slicer.util.getNode(reference)
>     multiImage=multiNode.GetImageData()
>     N=multiNode.GetNumberOfFrames()
>     for i in range (N):    #extract image
>         im=vtk.vtkImageExtractComponents()
>         im.SetInputData(multiImage)
>         im.SetComponents(i)
>         im.Update()
>         frame=slicer.modules.volumes.logic().CloneVolume(slicer.mrmlScene,refNode,'frame_'+str(i))
>         frame.SetAndObserveImageData(im.GetOutput())
>     label=su.PullFromSlicer(label)
>     Image_size=label.GetSize()  #get distance between the label map and the image border
>     xl_min=Image_size[0]      
>     xl_max=0 
>     yl_min=Image_size[1] 
>     yl_max=0 
>     zl_min=Image_size[2]
>     zl_max=0
>     for i in range(Image_size[0]):
>         for j in range(Image_size[1]):
>             for k in range(Image_size[2]):
>                 if (label.GetPixel(i,j,k)!=0):
>                     if( xl_min>i): 
>                         xl_min=i
>                     if( xl_max<i): 
>                         xl_max=i
>                     if( yl_min>j): 
>                         yl_min=j
>                     if( yl_max<j): 
>                         yl_max=j
>                     if( zl_min>k): 
>                         zl_min=k
>                     if( zl_max<k): 
>                         zl_max=k
>     for i in range(N):                  #crop the image              
>         im=su.PullFromSlicer('frame_'+str(i))
>         im_Crop=sitk.Crop(im,[ xl_min,yl_min,zl_min ],[Image_size[0]-xl_max, Image_size[1]-yl_max, Image_size[2]-zl_max ])  
>         su.PushToSlicer(im_Crop,"frame_crop_"+str(i),1)
>     im=su.PullFromSlicer('frame_crop_'+str(N-1)) #register
>     su.PushToSlicer(im,"frame_recal_"+str(N-1),1)
>     for f in range(N-1):
>         f0=slicer.util.getNode('frame_crop_'+str(N-1-f))
>         f1=slicer.util.getNode('frame_crop_'+str(N-2-f))
>         parameters = {}
>         parameters["fixedVolume"] = f0
>         parameters["movingVolume"] = f1
>         #parameters["useRigid"] = True
>     parameters["useScaleSkewVersor3D"]=True
>         parameters["useAffine"]=True
>     parameters["useBSpline"]=True
>       parameters["samplingPercentage"]=0.1
>         #parameters["initializeTransformMode"] = "useMomentsAlign"
>         parameters["backgroundFillValue"] = 0       
>         registeredObiNode = slicer.vtkMRMLScalarVolumeNode()
>         slicer.mrmlScene.AddNode(registeredObiNode)
>         registeredObiNode.SetName('frame_recal_'+str(multiNode.GetNumberOfFrames()-2-f))
>         parameters["outputVolume"] = registeredObiNode.GetID()
>         brainsFit = slicer.modules.brainsfit
>         cliBrainsFitRigidNode = None
>         cliBrainsFitRigidNode = slicer.cli.run(brainsFit, None, parameters)
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20150327/ea36cec7/attachment.html>


More information about the Community mailing list