<div dir="ltr"><div>Hi all,<br></div><div>Regarding that example, I am trying to replicate it but in Python. For that I did the following:<br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style><br>
</div><div class="gmail_extra" style><div class="gmail_extra"> spacing = np.zeros(3)</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>whiteImage = vtk.vtkImageData()</div>
<div class="gmail_extra"><span class="" style="white-space:pre">                </span>bounds = self.dsurf.dense_representation_grid.GetBounds() # self.dsurf.dense_representation_grid is my vtkPolyData represented in red in the attached image</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>spacing[0] = 0.0960<span class="" style="white-space:pre">                </span># desired volume spacing (.mha info): ElementSpacing = 0.0960 0.0968 0.0726</div>
<div class="gmail_extra"><span class="" style="white-space:pre">                </span>spacing[1] = 0.0968</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>spacing[2] = 0.0726</div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>whiteImage.SetSpacing(spacing)</div><div class="gmail_extra"><span class="" style="white-space:pre">        </span></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span># Compute dimensions:<span class="" style="white-space:pre">        </span></div>
<div class="gmail_extra"><span class="" style="white-space:pre">                </span>dim = []</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>dim.append((bounds[1] - bounds[0])/spacing[0])</div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>dim.append((bounds[3] - bounds[2])/spacing[1])</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>dim.append((bounds[5] - bounds[4])/spacing[2])</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>whiteImage.SetDimensions(dim)</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>whiteImage.SetExtent(0, dim[0]-1,0,dim[1]-1,0,dim[2]-1)</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>origin = np.zeros(3)</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>origin[0] = bounds[0] + spacing[0] / 2;</div>
<div class="gmail_extra"> <span class="" style="white-space:pre">                </span>origin[1] = bounds[2] + spacing[1] / 2;</div><div class="gmail_extra"> <span class="" style="white-space:pre">                </span>origin[2] = bounds[4] + spacing[2] / 2;</div>
<div class="gmail_extra"> <span class="" style="white-space:pre">                </span>whiteImage.SetOrigin(origin)</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>whiteImage.SetScalarTypeToUnsignedChar()</div>
<div class="gmail_extra"><span class="" style="white-space:pre">                </span>whiteImage.AllocateScalars()</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>inval = 255;</div>
<div class="gmail_extra"> <span class="" style="white-space:pre">                </span>outval = 0;</div><div class="gmail_extra"> <span class="" style="white-space:pre">                </span>count = whiteImage.GetNumberOfPoints()</div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>for i in range(0,count):</div><div class="gmail_extra"> <span class="" style="white-space:pre">                        </span>whiteImage.GetPointData().GetScalars().SetTuple1(i, inval)</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span># polygonal data --> image stencil:</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>pol2stenc = vtk.vtkPolyDataToImageStencil()</div>
<div class="gmail_extra"><span class="" style="white-space:pre">                </span>pol2stenc.SetInput(self.dsurf.dense_representation_grid)</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>pol2stenc.SetOutputOrigin(origin)</div>
<div class="gmail_extra"> <span class="" style="white-space:pre">                </span>pol2stenc.SetOutputSpacing(spacing)</div><div class="gmail_extra"> <span class="" style="white-space:pre">                </span>pol2stenc.SetOutputWholeExtent(whiteImage.GetExtent())</div>
<div class="gmail_extra"> <span class="" style="white-space:pre">                </span>pol2stenc.Update()</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">                </span># cut the corresponding white image and set the background:</div>
<div class="gmail_extra"><span class="" style="white-space:pre">                </span>imgstenc = vtk.vtkImageStencil()</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>imgstenc.SetInput(whiteImage)</div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>imgstenc.SetStencil(pol2stenc.GetOutput())</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>imgstenc.ReverseStencilOff()</div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>imgstenc.SetBackgroundValue(0)</div><div class="gmail_extra"> <span class="" style="white-space:pre">                </span>imgstenc.Update()</div><div class="gmail_extra"> </div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>writer = vtk.vtkMetaImageWriter()</div><div class="gmail_extra"> <span class="" style="white-space:pre">                </span>writer.SetFileName("SphereVolume.mhd")</div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>writer.SetInput(imgstenc.GetOutput())</div><div class="gmail_extra"><span class="" style="white-space:pre">                </span>writer.Write()</div><div class="gmail_extra"><br></div><div class="gmail_extra">
<span class="" style="white-space:pre">                </span>writer2 = vtk.vtkPNMWriter()</div><div class="gmail_extra"> <span class="" style="white-space:pre">        </span>writer2.SetInput(imgstenc.GetOutput())</div><div class="gmail_extra">
<span class="" style="white-space:pre">        </span>writer2.SetFileName("SphereVolume.pgm")</div><div class="gmail_extra"> <span class="" style="white-space:pre">        </span>writer2.Write()</div><div class="gmail_extra">
<br></div><div class="gmail_extra"><br></div><div class="gmail_extra" style>The problem is that the image created at the end is just a small (compared to the hxw of the plane I really want in the 3D volume) black image. Can anyone tell me, looking at the C++ code of that example, what is wrong here?</div>
<div class="gmail_extra"><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData" target="_blank" style="font-family:verdana,sans-serif">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData</a><br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra" style>PS: David G., sorry to add you (2x) to this, but usually you are the one who save me when it comes to Python :)</div>
<div><br></div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 22 May 2013 11:58, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:verdana,sans-serif;font-size:small">
Is this what you are looking for?</div><div style="font-family:verdana,sans-serif;font-size:small"><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData</a><br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Wed, May 22, 2013 at 12:30 PM, shirani kannangara <span dir="ltr"><<a href="mailto:mangalika673@gmail.com" target="_blank">mangalika673@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">HI <div>I have created a mesh model of liver(.vtk file) with poly data from VHP Abdomen.mhd file.Now I want to make a binary image of it.I checked VTK C++ examples to find a sample program.But so far failed.Can you please help me to convert this vtk mesh model into a binary image.</div>
<div><br></div><div>thanks in advance</div><div><br></div><div>regards</div><span><font color="#888888"><div><br></div><div>shirani</div></font></span></div>
<br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><br>____________<br><br>João Domingos<br>DPhil candidate<br>Institute of Biomedical Engineering<br>Department of Engineering Science<br>University of Oxford, UK<br>
<br>Email: <a href="mailto:domingos.domingos@eng.ox.ac.uk" target="_blank">domingos.domingos@eng.ox.ac.uk</a><br>Mobile: <a value="+447946252288">+44(0) 794 625 2288</a><br><br>Wolfson College<br>Linton Road<br>Oxford<br>
OX2 6UD<br>United Kingdom</div>
</div></div>