<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">David,<div class=""><br class=""></div><div class="">To minimise computing time, I would like to then shrink my kernel after resampling it.</div><div class=""><br class=""></div><div class="">Is there a method in VTK to reduce a vtkImageData’s extent, such that the cuboid is smallest possible without omitting any non-zero voxels (as in the images below).</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Richard</div><div class=""><br class=""></div><div class=""><img apple-inline="yes" id="A9BBEBB6-05D0-41EE-939C-32FEB2B9027E" height="373" width="395" apple-width="yes" apple-height="yes" src="cid:EE561642-F475-451C-9A5D-66527CD165CF@inserm.lan" class=""><img apple-inline="yes" id="02D802B8-44C7-4007-AE4E-3B0238985C7D" height="162" width="162" apple-width="yes" apple-height="yes" src="cid:83B2CB54-77A4-4437-B204-97593D384743@inserm.lan" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 20 Jul 2016, at 16:58, David Gobbi <<a href="mailto:david.gobbi@gmail.com" class="">david.gobbi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Richard,<div class=""><br class=""></div><div class="">Yes, the resampled kernel will be the full size of your dose grid. To avoid this, you would have to compute for yourself what the bounds of the resampled kernel are, and then use the reslice->SetOutputExtent() method to declare those bounds. Or, you could avoid using vtkImageReslice altogether and use vtkImageInterpolator directly instead.</div><div class=""><br class=""></div><div class="">The best option, if your kernel is defined by an analytic function, is to transform the x,y,z coords of that function and evaluate the dose directly on your grid.</div><div class=""><br class=""></div><div class=""> - David</div><div class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Jul 20, 2016 at 8:11 AM, Richard Brown <span dir="ltr" class=""><<a href="mailto:richard.j.brown@live.co.uk" target="_blank" class="">richard.j.brown@live.co.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">David,<div class=""><br class=""></div><div class="">That sorted it, thanks. </div><div class=""><br class=""></div><div class="">So the resampled kernel has the same dimensions as the dose grid? My kernel is very small compared to my dose grid, so superposition will be slower than necessary. </div><div class=""><br class=""></div><div class="">Is this why, in your original response, you said the method isn’t very fast if it needs to be used many times?</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Richard</div><div class=""><div class="h5"><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 20 Jul 2016, at 16:01, David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank" class="">david.gobbi@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hi Richard,<div class=""><br class=""></div><div class="">SetInformationInput(), not SetInformation(). The former (the one you need to use) requires a vtkImageData as input. It provides the reference image that defines the geometry for the reslicing.</div><div class=""><br class=""></div><div class=""> - David</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Jul 20, 2016 at 7:55 AM, Richard Brown <span dir="ltr" class=""><<a href="mailto:richard.j.brown@live.co.uk" target="_blank" class="">richard.j.brown@live.co.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Hi David, <div class=""><br class=""></div><div class="">I’ve been working through your advice and I get an error:</div><div class=""><span style="white-space:pre-wrap" class=""> </span><span style="font-family:Menlo;font-size:14px" class="">Attempt to get an input array for an index that has not been specified</span></div><div class=""><span style="font-family:Menlo;font-size:14px" class=""><br class=""></span></div><div class="">My code looks like yours:</div><div class=""><span style="white-space:pre-wrap" class=""> </span> <span style="color:rgb(128,0,128)" class="">vtkSmartPointer</span><<span style="color:rgb(128,0,128)" class="">vtkImageReslice</span>><span style="color:rgb(192,192,192)" class=""> </span>imageReslice<span style="color:rgb(192,192,192)" class=""> </span>=<span style="color:rgb(192,192,192)" class=""> </span><span style="color:rgb(128,0,128)" class="">vtkSmartPointer</span><<span style="color:rgb(128,0,128)" class="">vtkImageReslice</span>>::New();</div>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>imageReslice->SetInputData(kernelImageData);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>imageReslice-><span style="font-style:italic" class="">SetInformation</span>(doseGrid-><span style="font-style:italic" class="">GetInformation</span>());</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>imageReslice->SetInterpolationModeToLinear();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>imageReslice-><span style="font-style:italic" class="">SetResliceTransform</span>(transform);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>imageReslice-><span style="font-style:italic" class="">Update</span>();</pre><div class=""><br class=""></div><div class="">It seems like the error is coming from doseGrid (when I comment it out, the error goes away). The dose grid was initialised like this:</div><div class="">
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#800080" class=""> vtkSmartPointer</span><<span style="color:#800080" class="">vtkImageData</span>><span style="color:#c0c0c0" class=""> </span>doseGrid<span style="color:#c0c0c0" class=""> </span>=<span style="color:#c0c0c0" class=""> </span><span style="color:#800080" class="">vtkSmartPointer</span><<span style="color:#800080" class="">vtkImageData</span>>::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>doseGrid-><span style="font-style:italic" class="">SetOrigin</span>(<span style="color:#000080" class="">0.</span>,<span style="color:#000080" class="">0.</span>,<span style="color:#000080" class="">0.</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>doseGrid-><span style="font-style:italic" class="">SetDimensions</span>(<span style="color:#000080" class="">500</span>,<span style="color:#000080" class="">500</span>,<span style="color:#000080" class="">500</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>doseGrid-><span style="font-style:italic" class="">SetSpacing</span>(<span style="color:#000080" class="">0.5</span>,<span style="color:#000080" class="">0.5</span>,<span style="color:#000080" class="">0.5</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class=""> </span>doseGrid-><span style="font-style:italic" class="">AllocateScalars</span>(<span style="color:#000080" class="">VTK_DOUBLE</span>,<span style="color:#000080" class="">1</span>);</pre><div class=""><br class=""></div></div><div class="">Any idea what I’ve done wrong?</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Richard</div><div class=""><div class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 08 Jul 2016, at 17:42, David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank" class="">david.gobbi@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hi Richard,<div class=""><br class=""></div><div class="">Yes, you can use vtkImageReslice for this. It would work like this:</div><div class=""><br class=""></div><div class="">Let's define T as the transform that gives the position and orientation of the kernel within the larger image. To resample the kernel, you would give vtkImageReslice the inverse of T as the ResliceTransform, and you would supply the larger image as a reference image, e.g. the code would look like this (using Python):</div><div class=""><br class=""></div><div class="">reslice = vtkImageReslice()</div><div class="">reslice.SetInputData(kernel_image)</div><div class="">reslice.SetInformationInput(big_image)</div><div class="">reslice.SetResliceTransform(inverse_transform)</div><div class="">reslice.SetInterpolationModeToLinear()</div><div class="">reslice.Update()</div><div class=""><br class=""></div><div class="">This will produce something like the bottom image from your original email. In order for the kernel resampling to work properly, your kernel image must have a border which is all zeros. If this must be done over and over again (i.e. if you need to superimpose the kernel hundreds of times at various locations within the larger image) then the above procedure won't be fast enough. Another possibility is to use the vtkImageInterpolator class and some of your own ingenuity to create a fast method for resampling and superposing the kernel.</div><div class=""><br class=""></div><div class="">During my PhD, I wrote a custom VTK class that superposed kernels into a volume in order to do 3D ultrasound reconstruction, but I never generalized it:</div><div class=""><a href="https://github.com/dgobbi/AIGS/blob/master/Ultrasound/vtkFreehandUltrasound.h" target="_blank" class="">https://github.com/dgobbi/AIGS/blob/master/Ultrasound/vtkFreehandUltrasound.h</a></div><div class=""><br class=""></div><div class="">Some further development of this code was done for the PLUS toolkit:</div><div class=""><a href="https://app.assembla.com/spaces/plus/subversion/source/HEAD/trunk/PlusLib/src/PlusVolumeReconstruction" target="_blank" class="">https://app.assembla.com/spaces/plus/subversion/source/HEAD/trunk/PlusLib/src/PlusVolumeReconstruction</a></div><div class=""><br class=""></div><div class="">However, as far as I know, VTK doesn't provide an efficient general-purpose way of superposing kernels at different positions and orientations into a 3D volume.</div><div class=""><br class=""></div><div class=""> - David</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Jul 8, 2016 at 7:07 AM, Richard Brown <span dir="ltr" class=""><<a href="mailto:richard.j.brown@live.co.uk" target="_blank" class="">richard.j.brown@live.co.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><br class="">
Hi all,<div class=""><br class=""></div><div class="">I have a fairly simple problem, and one that I’m sure has previously been solved here, but I’m struggling to find the right keywords to find a useful thread.</div><div class=""><br class=""></div><div class="">I would like to superpose a kernel vtkImageData (kernel.png) onto a grid vtkImageData (grid.png). The kernel will be rotated (superpose.png), however, so the kernel will requiring resampling before superposition is possible (superposition_and_resample.png).</div><div class=""><br class=""></div><div class="">What is the best way to do this? I feel like I can simply use vtkImageReslice, but I’m not 100%. </div><div class=""><br class=""></div><div class="">Thanks in advance for any pointers.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Richard</div></div></blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></div></body></html>