<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello,<div><br></div><div>It's a bit hard to follow the code with how you have formatted. How big are your images?</div><div><br></div><div>1) Consider using LabelStatisticImageFilter to compute the bounding box.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Hope that helps,</div><div>Brad</div><div><br><div><div>On Mar 27, 2015, at 9:52 AM, Cyril Jaudet <<a href="mailto:drcjaudet@gmail.com">drcjaudet@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div><div><div><div>Hello itk community,<br><br></div>i use a python code to extract, crop, register and export 4d image. This code interact with 3Dslicer.<br></div>Do you know how optimize the memory management because it use more then 15Gb of memory when running ? <br><br></div>Thank you,<br></div><div style=""><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)" lang="NL-BE"> </span><br class="webkit-block-placeholder"></div>
<table class="" align="left" border="0" cellpadding="0" height="109" width="554">
<tbody><tr style="">
<td style="width:225pt;padding:0.75pt" width="300"><div style=""><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)"></span><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)"></span><br class="webkit-block-placeholder"></div>
<div class="MsoNormal" style="text-align:center" align="center"><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)">
<hr style="color:rgb(95,96,74)" align="center" noshade="" size="1" width="100%">
</span></div><p class="MsoNormal" style=""><b><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)">Cyril Jaudet<br>
</span></b><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)">Medical physicist, phd</span></p><p class="MsoNormal" style=""><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)"><br>
<a href="mailto:cyril.jaudet@uzbrussel.be"><span style="color:blue">cyril.jaudet@uzbrussel.be</span></a><br>
</span><span style="font-size:12pt;font-family:"Times New Roman","serif";color:rgb(95,96,74)"> </span></p><div class="MsoNormal" style="text-align:center" align="center"><span style="color:rgb(95,96,74)"><hr style="color:rgb(95,96,74)" align="center" noshade="" size="1" width="100%"></span></div></td><td style="padding:0cm"></td>
</tr>
<tr style="">
<td colspan="2" style="padding:0.75pt"><br></td>
</tr>
<tr style="">
<td colspan="2" style="padding:0.75pt"><br></td>
</tr>
</tbody></table>
<br><br><br><br>def CropAndRegister(multi,reference,label):<br> multiNode=slicer.util.getNode(multi)<br> refNode=slicer.util.getNode(reference)<br> multiImage=multiNode.GetImageData()<br> N=multiNode.GetNumberOfFrames()<br> for i in range (N): #extract image<br> im=vtk.vtkImageExtractComponents()<br> im.SetInputData(multiImage)<br> im.SetComponents(i)<br> im.Update()<br> frame=slicer.modules.volumes.logic().CloneVolume(slicer.mrmlScene,refNode,'frame_'+str(i))<br> frame.SetAndObserveImageData(im.GetOutput())<br> label=su.PullFromSlicer(label)<br> Image_size=label.GetSize() #get distance between the label map and the image border<br> xl_min=Image_size[0] <br> xl_max=0 <br> yl_min=Image_size[1] <br> yl_max=0 <br> zl_min=Image_size[2]<br> zl_max=0<br> for i in range(Image_size[0]):<br> for j in range(Image_size[1]):<br> for k in range(Image_size[2]):<br> if (label.GetPixel(i,j,k)!=0):<br> if( xl_min>i): <br> xl_min=i<br> if( xl_max<i): <br> xl_max=i<br> if( yl_min>j): <br> yl_min=j<br> if( yl_max<j): <br> yl_max=j<br> if( zl_min>k): <br> zl_min=k<br> if( zl_max<k): <br> zl_max=k<br> for i in range(N): #crop the image <br> im=su.PullFromSlicer('frame_'+str(i))<br> 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 ]) <br> su.PushToSlicer(im_Crop,"frame_crop_"+str(i),1)<br> im=su.PullFromSlicer('frame_crop_'+str(N-1)) #register<br> su.PushToSlicer(im,"frame_recal_"+str(N-1),1)<br> for f in range(N-1):<br> f0=slicer.util.getNode('frame_crop_'+str(N-1-f))<br> f1=slicer.util.getNode('frame_crop_'+str(N-2-f))<br> parameters = {}<br> parameters["fixedVolume"] = f0<br> parameters["movingVolume"] = f1<br> #parameters["useRigid"] = True<br> parameters["useScaleSkewVersor3D"]=True<br> parameters["useAffine"]=True<br> parameters["useBSpline"]=True<br> parameters["samplingPercentage"]=0.1<br> #parameters["initializeTransformMode"] = "useMomentsAlign"<br> parameters["backgroundFillValue"] = 0 <br> registeredObiNode = slicer.vtkMRMLScalarVolumeNode()<br> slicer.mrmlScene.AddNode(registeredObiNode)<br> registeredObiNode.SetName('frame_recal_'+str(multiNode.GetNumberOfFrames()-2-f))<br> parameters["outputVolume"] = registeredObiNode.GetID()<br> brainsFit = slicer.modules.brainsfit<br> cliBrainsFitRigidNode = None<br> cliBrainsFitRigidNode = slicer.cli.run(brainsFit, None, parameters)<br></div>
_______________________________________________<br>Community mailing list<br><a href="mailto:Community@itk.org">Community@itk.org</a><br>http://public.kitware.com/mailman/listinfo/community<br></blockquote></div><br></div></body></html>