<div dir="ltr"><div>Hi Greg,</div><div><br></div><div>I don't know of any diagrams for vtkImageReslice but I think that I can answer your questions.  First, though, I see a couple simple fixes for the code:<br></div><div><br></div><div>The length of a vector is the 2-norm of the vector (sqrt of sum of squares):</div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  np.linalg.norm(vv, 1)  should be</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  np.linalg.norm(vv, 2) or simply <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">np.linalg.norm(vv)</span></span></span><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">The call to vtkMath::Perpendiculars() from Python is done as follows, by creating the output value arrays and letting the method fill in the values:</span></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  u = np.zeros(3)</span></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  w = np.zeros(3)</span></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  vtk.vtkMath.Perpendiculars(nn, u, w, 0)</span></span></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div>With VTK's wrapping, if the C++ method returns values via the parameters, then the Python method always does the same.</div><div><br></div><div><br></div><div>With regards to SetOutputExtent(), the "Extent" in VTK is a set of six values [Xmin, Xmax, Ymin, Ymax, Zmin, Zmax] that give the limits of a block of voxels.  A line of N+1 voxels in the X direction that starts at zero is (0, N, 0, 0, 0, 0).  The X, Y, Z for the extent are voxel indices, i.e. they are integers.<br></div><div><br></div><div>So the Extent in VTK serves a similar purpose to the shape in numpy, with three fundamental differences:</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">1) The Extent is always 3D, whereas numpy arrays are ND</span><br></div><div>2) Extent has six values, since it gives the lower and upper value in each dimension rather than just giving the size in each dimension</div><div>3) The numpy shape is ordered from the slowest-varying to the fastest-varying index, whereas Extent is the opposite</div><div><br></div><div>An Extent of (0, Xsize-1, 0, Ysize-1, 0, Zsize-1) is equivalent to numpy shape of (Zsize, Ysize, Xsize) if the numpy array is C-contiguous.</div><div><br></div><div>Hopefully that didn't muddy up the issue too much.</div><div><br></div><div><br></div><div>About the Origin, its purpose here is as follows.  Let's say that you want to use three lines instead of one, to give the line some thickness in one direction:</div><div><br></div><div>  reslice.SetOutputExtent(0, N, 0, 2, 0, 0)  # gives a (N+1)*3*1 block of voxels</div><div><br></div><div>This block needs to be shifted so the middle line is the one at the desired position, and this shift is done by setting the Origin:</div><div><br></div><div>  reslice.SetOutputOrigin(0.0, -1.0*spacing[1], 0.0)</div><div><br></div><div>Setting the OutputOrigin like this causes the block to be shifted down by one sample spacing in the y direction.  More lines would require a larger shift.  Remember that the idea is that you the ResliceAxes transformation is going to put one end of this block at the desired starting point for your line.</div><div><br></div><div>And note that this block has to define a line (or lines) that go along the X-axis!  That's the whole point, since the transformation matrix will rotate this X-axis to the desired line orientation for your input image.  So get rid of the "if" statements that set up the extent in different directions, since the line orientation is already dealt with by the rotation in the transformation.</div><div><br></div><div> - David</div><div><br></div><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 3, 2018 at 10:16 PM, gregthom992 <span dir="ltr"><<a href="mailto:gregthom992@gmail.com" target="_blank">gregthom992@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 David,<br>
So I am almost there but there is some magic you have to explain to me. Is<br>
there some graphics that explans how imagereslice works ?<br>
<br>
For instance:<br>
How do you know to do<br>
<span class="gmail-">reslice.SetOutputExtent(0, N, 0, 0, 0, 0)  # this gives one line of output<br>
</span>and not<br>
reslice.SetOutputExtent(0, 0, 0, 0, 0, N)  # this gives one line of output<br>
<br>
Both give one line of output but I am lost here.<br>
<br>
Also:<br>
<br>
Please I know I can get multiple lines for instance 2 lines by:<br>
reslice.SetOutputExtent(0, N, 0, 1, 0, 0)  # this gives two lines of output<br>
<br>
What were you saying about fiddling with origin ? Below is my complete code<br>
which doesn't give me the expected results<br>
<br>
<br>
<br>
===================<br>
<br>
            vtkimage = SITKtoVTK(itkimage)<br>
            vtkimage.SetOrigin(itkimage.<wbr>GetOrigin())<br>
            print itkimage<br>
            print vtkimage<br>
<br>
            p0 = np.array(prf_start)<br>
            p1 = np.array(prf_stop)<br>
            vv = p1 - p0<br>
            nn = vv/np.linalg.norm(vv, 1)<br>
<br>
            u, w = vtkMathPerpendiculars(nn, 3*[0], 3*[0], 0)<br>
<br>
            #print vtkimage, itkimage<br>
            print vv<br>
            print nn<br>
            print u, ' ',  w<br>
            #<br>
            oM2 = vtk.vtkMatrix4x4()<br>
            oM2.DeepCopy((<br>
                nn[0], u[0], w[0], p0[0],<br>
                nn[1], u[1], w[1], p0[1],<br>
                nn[2], u[2], w[2], p0[2],<br>
                0, 0, 0, 1 ))<br>
            print oM2<br>
            #<br>
            reslice = vtk.vtkImageReslice()<br>
            reslice.SetInput(vtkimage)<br>
            #reslice.SetOutputOrigin(<wbr>itkimage.GetOrigin()[0],<br>
itkimage.GetOrigin()[1], itkimage.GetOrigin()[2])<br>
            reslice.SetOutputOrigin(0, 0, 0)<br>
            reslice.SetOutputSpacing(<wbr>itkimage.GetSpacing()[0],<br>
itkimage.GetSpacing()[1], itkimage.GetSpacing()[2])<br>
            if prf_params[0] in ['depth']:<br>
                reslice.SetOutputExtent(0, itkimage.GetDepth()-1, 0, 0, 0,<br>
<span class="gmail-">0)  # this gives one line of output<br>
</span>            if prf_params[0] in ['inline']:<br>
                reslice.SetOutputExtent(0, 0, 0, itkimage.GetHeight()-1, 0,<br>
<span class="gmail-">0)  # this gives one line of output<br>
</span>            if prf_params[0] in ['crossline']:<br>
                reslice.SetOutputExtent(0, 0, 0, 0, 0,<br>
itkimage.GetWidth()-1)  # this gives one line of output<br>
            reslice.<wbr>SetInterpolationModeToLinear()<br>
            reslice.SetResliceAxes(oM2)<br>
            reslice.Update()<br>
            vtkimage2 = reslice.GetOutput()<br>
<br>
            print vtkimage2<br>
<br>
            numpy_data =<br>
numpy_support.vtk_to_numpy(<wbr>vtkimage2.GetPointData().<wbr>GetScalars())<br>
<br>
            print numpy_data<br></blockquote></div></div></div>