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

Cyril Jaudet drcjaudet at gmail.com
Fri Mar 27 09:52:57 EDT 2015


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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20150327/21ac4bfe/attachment.html>


More information about the Community mailing list