<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>
<p class="MsoNormal" style><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)" lang="NL-BE"> </span></p>
<table class="" align="left" border="0" cellpadding="0" height="109" width="554">
<tbody><tr style>
<td style="width:225pt;padding:0.75pt" width="300">
<p class="MsoNormal" 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></p>
<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>