[vtkusers] probe volume with thick line ( intensity profile with line radius or thickness )

David Gobbi david.gobbi at gmail.com
Sat Feb 3 19:23:44 EST 2018

Hi Greg,

Rotating the image will work, and you wouldn't have to rotate the entire
image, since you're only interested in certain pixels.

The filter vtkImageReslice will translate and rotate an image via
interpolation, and you can set it up so that the output is just one single
line (or several lines, to make a thick line).  The tricky part is finding
the correct rotation and translation for SetResliceAxes().  It could be
done as follows:

First, note that the direction of the ResliceAxes transformation is
Output->Input (ditto for ResliceTransform, it does the same thing).

The translation part of the transformation is easy: if the output of
vtkImageReslice is a line of pixels (voxels) starting at (0,0,0), then we
want a translation that moves point (0,0,0) to (px,py,pz) where the latter
is the starting point of the profile line.

And to keep the rotation simple, the output of vtkImageReslice can be one
line of pixels along the x-axis, and then we want a rotation that will
rotate a unit x-axis vector to the direction vector of the profile line.
It's possible to compute the rotation between vectors by doing a cross
product, but fortunately there is a method, vtkMath::Perpendiculars(), that
can easily do what we need when one of the vectors happens to be the x-axis

So let's say the profile line starts at (px,py,pz) and has a unit direction
vector of (vx,vy,vz).  The needed ResliceAxes transformation will be as

double resliceAxesValues[16] = {
  vx, ux, wx, px,
  vy, uy, wy, py,
  vz, uz, wz, pz,
  0, 0, 0, 1 };

We already have (px, py, pz) as the translation part of the 4x4 matrix, and
(vx, vy, vz) as the first column of the 3x3 rotation matrix.  The
aforementioned vtkMath::Perpendiculars() method can be used to compute
suitable "u" and "w" values:

// compute vectors u, w that are perpendicular to an existing vector v:
double u[3], w[3];
vtkMath::Perpendiculars(v, u, w, 0.0);

If you wanted to do just a single line via a rotation of the image, you
could do it like this:

reslice = vtk.vtkImageReslice()
reslice.SetInputConnection( ... )
reslice.SetOutputOrigin(0, 0, 0)
reslice.SetOutputSpacing( ...) # use original image spacing
reslice.SetOutputExtent(0, N, 0, 0, 0, 0)  # this gives one line of output
reslice.SetResliceAxes( ... )

The output of vtkImageReslice will be the values along the line.  Fiddling
with Origin and OutputExtent can do several lines at once.

 - David

On Sat, Feb 3, 2018 at 4:33 PM, gregthom992 <gregthom992 at gmail.com> wrote:

> Thanks David,
> I think  your idea is certainly interesting and I want to work on it later
> after the current idea I just had.
> Right now the idea I had was to first orient (rotate ) image so that it is
> aligned with the line. After which I intend to simply get rows from the
> rotated image. I am not sure how this will work.
> I am still reading how to build this pipeline. Do you have any pointers to
> speed this up for me ?
> Thanks
> GT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180203/7eb1bdf5/attachment.html>

More information about the vtkusers mailing list