<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 Cyril,<div><br></div><div><br></div><div><br><div><div>On Mar 27, 2015, at 10:23 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><div>Thank for you fast reply.<br><br></div>Image size are 512x512x224x22 voxels...<br></div></div></div></div></div></blockquote><div><br></div><div>OK so your data is 1.2GB? maybe 2.4GB if short? or 4.8 if converted to float?</div><br><blockquote type="cite"><div dir="ltr"><div><div><div><div><br>1) This is a good idea but i don't know how to use SimpleITK crop image filter with a bounding box as input?<br></div></div></div></div></div></blockquote><div><br></div><div>The format of the bounding box is defined here:</div><div><a href="http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1LabelStatisticsImageFilter.html#ae117448f17ba708a7364e90bfaaa44af">http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1LabelStatisticsImageFilter.html#ae117448f17ba708a7364e90bfaaa44af</a></div><div><br></div><div>Should be straight forward enough to convert that info to the parameters for CropImageFilter or ExtractImageFilter.</div><br><blockquote type="cite"><div dir="ltr"><div><div><div><div><br></div>2) You're right but i don't know how delete the image i don't need any more.<br></div></div></div></div></blockquote><div><br></div><div>For SimpleITK just use 'del':</div><div><a href="https://docs.python.org/2/tutorial/datastructures.html?highlight=del#the-del-statement">https://docs.python.org/2/tutorial/datastructures.html?highlight=del#the-del-statement</a></div><br><blockquote type="cite"><div dir="ltr"><div><div><div> <br>3)Indeed the problem come from a mixing of vtk image to go from 4d to 3d, simple itk to crop them and vtk to use slicer module to register them. <br></div></div></div></div></blockquote><div><br></div><div>Maybe you could use SimpleITK registration to avoid the pushing to slicer and evoking the slicer module, if your registration problem is simple enough?</div><br><blockquote type="cite"><div dir="ltr"><div><div><br>Do you have a clue to transform the vtk image in simple itk format? In the forum  a convert option suggested was to pass by numpy but i think it's really an indirect/ no efficient way.<br></div></div></div></blockquote><div><br></div><div>I would think going through numpy would be better than pushing into Slicer MRML. But those are currently the two ways to do it. I have been hoping some one would implement a more efficient way.</div><br><blockquote type="cite"><div dir="ltr"><div><div><br></div><div>Also i would like to keep the convertion to simple itk format before calling the slicer module beacause it allow to use another itk filter for denoising or change format purpose.<br><br></div><div></div><div>Thank for your help,<br></div><div>Cyril<br></div></div><br><div><br> <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-27 15:05 GMT+01:00 Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">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><div class="h5"><div>On Mar 27, 2015, at 9:52 AM, Cyril Jaudet <<a href="mailto:drcjaudet@gmail.com" target="_blank">drcjaudet@gmail.com</a>> wrote:</div><br></div></div><blockquote type="cite"><div><div class="h5"><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><span style="font-size:9pt;font-family:"Lucida Sans Unicode","sans-serif";color:rgb(95,96,74)" lang="NL-BE"> </span><br></div>

<table align="left" border="0" cellpadding="0" height="109" width="554">
 <tbody><tr>
  <td style="width:225pt;padding:0.75pt" width="300"><div><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></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"><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"><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" target="_blank"><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>
  <td colspan="2" style="padding:0.75pt"><br></td>
 </tr>
 <tr>
  <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></div></div>
_______________________________________________<br>Community mailing list<br><a href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br><a href="http://public.kitware.com/mailman/listinfo/community" target="_blank">http://public.kitware.com/mailman/listinfo/community</a><br></blockquote></div><br></div></div></blockquote></div><br></div>
</blockquote></div><br></div></body></html>