<div dir="ltr"><div>Thanks for your help Kenichiro Yoshimi</div><div><br></div><div>I was able to reproduce some part of your code. However, I encountered new issues.</div><div><br></div><div>1)I have all my project under VTK 5.10.1 with python 2.7.12 in linux. I got this error: 'module' object has no attribute 'vtkResampleToImage'.</div><div> So I guess that the vtkResampleToImage class is not avaliable for my VTK version. </div><div> I tried to build a newer VTK version but I didn't get success. I tried with VTK 7.1.1 and I got errors related to the python libs Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS). </div><div> </div><div>2) I read that vtkResampleToImage samples a dataset on a uniform grid and it internally uses vtkProbeFilter to do the probing. So, Is there any way to use vtkProbeFilter instead of vtkResampleToImage?</div><div>I have tested some examples from vtkProbeFilter but I am confused about how use it in my specific problem.</div><div><br></div><div>Thanks,</div><div><br></div><div>Lizeth</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 19, 2018 at 12:38 AM, kenichiro yoshimi <span dir="ltr"><<a href="mailto:rccm.kyoshimi@gmail.com" target="_blank">rccm.kyoshimi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Lizeth,<br>
<br>
Because vtkDelimitedTextReader outputs a vtkTable, you firstly need to<br>
convert it to a vtkPolyData using vtkTableToPolyData. And then you can<br>
use vtkResampleToImage to map the polyData to vtkImageData.<br>
<br>
---sample.csv---<br>
0 0 0 60.7635<br>
1 0 0 107.555<br>
2 0 0 80.5241<br>
0 1 0 85.9694<br>
1 1 0 156.706<br>
2 1 0 105.73<br>
0 2 0 37.3531<br>
1 2 0 84.1445<br>
2 2 0 57.1137<br>
0 0 1 100.634<br>
1 0 1 171.37<br>
2 0 1 120.395<br>
0 1 1 149.785<br>
1 1 1 260<br>
2 1 1 169.546<br>
0 2 1 77.2238<br>
1 2 1 147.96<br>
2 2 1 96.9844<br>
0 0 2 60.7635<br>
1 0 2 107.555<br>
2 0 2 80.5241<br>
0 1 2 85.9694<br>
1 1 2 156.706<br>
2 1 2 105.73<br>
0 2 2 37.3531<br>
1 2 2 84.1445<br>
2 2 2 57.1137<br>
<br>
---<br>
import vtk<br>
<br>
<br>
def main():<br>
colors = vtk.vtkNamedColors()<br>
<br>
reader = vtk.vtkDelimitedTextReader()<br>
reader.SetFileName('sample.csv<wbr>')<br>
reader.DetectNumericColumnsOn(<wbr>)<br>
reader.SetFieldDelimiterCharac<wbr>ters(' ')<br>
reader.MergeConsecutiveDelimit<wbr>ersOn()<br>
<br>
tableToPoints = vtk.vtkTableToPolyData()<br>
tableToPoints.SetInputConnecti<wbr>on(reader.GetOutputPort())<br>
tableToPoints.SetXColumn('Fiel<wbr>d 0')<br>
tableToPoints.SetYColumn('Fiel<wbr>d 1')<br>
tableToPoints.SetZColumn('Fiel<wbr>d 2')<br>
<br>
resample = vtk.vtkResampleToImage()<br>
resample.SetInputConnection(ta<wbr>bleToPoints.GetOutputPort())<br>
resample.SetSamplingDimensions<wbr>(3, 3, 3)<br>
resample.Update()<br>
<br>
scalar = resample.GetOutput().GetPointD<wbr>ata().GetArray('Field 3')<br>
resample.GetOutput().GetPointD<wbr>ata().SetScalars(scalar)<br>
<br>
writer = vtk.vtkMetaImageWriter()<br>
writer.SetInputData(resample.G<wbr>etOutput())<br>
writer.SetFileName('out.mha')<br>
writer.SetCompression(True)<br>
writer.Write()<br>
<br>
<br>
if __name__ == '__main__':<br>
main()<br>
---<br>
<br>
Best<br>
2018年7月19日(木) 3:43 Lizeth Castellanos <<a href="mailto:castellanoslizan@gmail.com" target="_blank">castellanoslizan@gmail.com</a>>:<br>
<div><div class="m_2822685787072492960gmail-h5">><br>
> Hi!<br>
><br>
> I'd like to copy image data from a textfile (csv) into vtkImageData.<br>
> The textfile have voxel values for x,y,z and image intensity. I already have read the textfile into VTK with the vtkDelimitedTextReader class:<br>
><br>
> Table loaded from CSV file:<br>
> +-----------+-----------+-----<wbr>------+------------+<br>
> | Field 0 | Field 1 | Field 2 | Field 3 |<br>
> +-----------+-----------+-----<wbr>------+------------+<br>
> | 510 | 291 | 0 | 32 |<br>
> | 511 | 291 | 0 | 128 |<br>
> | 510 | 292 | 0 | 104 |<br>
> | 511 | 292 | 0 | 104 |<br>
> | 510 | 293 | 0 | 40 |<br>
> | 511 | 293 | 0 | 240 |<br>
> | 510 | 294 | 0 | 104 |<br>
> | 511 | 294 | 0 | 96 |<br>
> | 506 | 295 | 0 | 64 |<br>
> | 507 | 295 | 0 | 16 |<br>
> .....<br>
> .....<br>
> The file is an exported segmented dataset.<br>
><br>
> I am following the tips from this similar question <a href="http://vtk.1045678.n5.nabble.com/importing-image-data-into-VTK-from-textfile-mimics-td1243332.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.c<wbr>om/importing-image-data-into-V<wbr>TK-from-textfile-mimics-td1243<wbr>332.html</a><br>
> I have created an appropriate vtkimagedata (volume):<br>
><br>
> imageData = vtk.vtkImageData()<br>
> imageData.SetDimensions(512, 512, 192)<br>
> imageData.SetOrigin(0.0, 0.0, 0.0)<br>
> imageData.SetSpacing(1, 1, 1)<br>
> imageData.SetNumberOfScalarCom<wbr>ponents(1)<br>
> imageData.Update()<br>
><br>
> However I don't know how to copy the data loaded from vtkDelimitedTextReader into vtkImageData. How do I copy the x,y,z voxel values into vtkImageData? How do I copy the intensity valuesVtkImageData?<br>
><br>
> Any help provided for this would be greatly appreciated!<br>
><br>
> Lizeth<br>
><br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/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" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FA<wbr>Q</a><br>
><br>
> Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/mai<wbr>lman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_2822685787072492960gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div><br></div><div><br></div></div></div></div></div></div>
</div></div>