<div dir="ltr">Hi Sankhesh,<div><br></div><div>Thank you for your comment. Can you tell me how I can adjust the spacing of the image data along the z-axis?</div><div>Below is my code:</div><div><br></div><div><div>from PyQt5.QtWidgets import (QMainWindow,</div><div> QFrame, QVBoxLayout, QApplication)</div><div>from PyQt5 import QtCore</div><div>from QVTKRenderWindowInteractor import QVTKRenderWindowInteractor</div><div>import random<br></div><div>import vtk</div><div>import numpy as np</div><div>import sys</div><div>import h5py</div><div>import skimage</div><div>import matplotlib.pyplot as plt</div><div><br></div><div><br></div><div>def misc2stdimage(img):</div><div> '''</div><div> Transform arbitrarily scaled image into</div><div> something scikit image understands, </div><div> ie. a ubyte numpy array</div><div> '''</div><div> # rescale to [x E -1.0;1.0], xER</div><div> img_rescaled = (((img - img.min()) / (img.max() - img.min()))*2)-1 </div><div> return skimage.img_as_ubyte(img_rescaled)</div><div><br></div><div>class MyEventFilter(QtCore.QObject):</div><div> def __init__(self, vtkwindow):</div><div> self.vtkwindow = vtkwindow</div><div> QtCore.QObject.__init__(self)</div><div> </div><div> def eventFilter(self, receiver, event):</div><div> if(event.type() == QtCore.QEvent.KeyPress):</div><div> if event.text() == 'x':</div><div> self.vtkwindow.slideX(1)</div><div> elif event.text() == 'X':</div><div> self.vtkwindow.slideX(-1)</div><div> elif event.text() == 'y':</div><div> self.vtkwindow.slideY(1)</div><div> elif event.text() == 'Y':</div><div> self.vtkwindow.slideY(-1)</div><div> elif event.text() == 'z':</div><div> self.vtkwindow.slideZ(1)</div><div> elif event.text() == 'Z':</div><div> self.vtkwindow.slideZ(-1)</div><div> return super(MyEventFilter,self).eventFilter(receiver, event)</div><div><br></div><div>def MakeLUTFromCTF(tableSize):</div><div> '''</div><div> Use a color transfer Function to generate the colors in the lookup table.</div><div> See: <a href="http://www.vtk.org/doc/nightly/html/classvtkColorTransferFunction.html">http://www.vtk.org/doc/nightly/html/classvtkColorTransferFunction.html</a></div><div> :param: tableSize - The table size</div><div> :return: The lookup table.</div><div> '''</div><div> ctf = vtk.vtkColorTransferFunction()<br></div><div> ctf.SetColorSpaceToDiverging()</div><div> # Green to tan.</div><div> ctf.AddRGBPoint(0.0, 0.085, 0.532, 0.201)</div><div> ctf.AddRGBPoint(0.5, 0.865, 0.865, 0.865)</div><div> ctf.AddRGBPoint(1.0, 0.677, 0.492, 0.093)</div><div> </div><div> lut = vtk.vtkLookupTable()</div><div> lut.SetNumberOfTableValues(tableSize)</div><div> lut.Build()</div><div> </div><div> for i in range(0,tableSize):</div><div> rgb = list(ctf.GetColor(float(i)/tableSize))+[1]</div><div> lut.SetTableValue(i,rgb)</div><div> </div><div> return lut</div><div><br></div><div>class MainWindow(QMainWindow):</div><div><br></div><div> def slideX(self, x):</div><div> self.planeWidgetX.SetSliceIndex(</div><div> self.planeWidgetX.GetSliceIndex() + x</div><div> )</div><div> print( self.planeWidgetX.GetSliceIndex() )</div><div> self.ren.ResetCameraClippingRange()</div><div> self.vtkWidget.GetRenderWindow().Render()</div><div><br></div><div> def slideY(self, y):</div><div> self.planeWidgetY.SetSliceIndex(</div><div> self.planeWidgetY.GetSliceIndex() + y</div><div> )</div><div> self.ren.ResetCameraClippingRange()</div><div> self.vtkWidget.GetRenderWindow().Render()</div><div><br></div><div> def slideZ(self, z):</div><div> self.planeWidgetZ.SetSliceIndex(</div><div> self.planeWidgetZ.GetSliceIndex() + z</div><div> )</div><div> self.ren.ResetCameraClippingRange()</div><div> self.vtkWidget.GetRenderWindow().Render()</div><div> </div><div> def __init__(self, parent = None):</div><div> QMainWindow.__init__(self, parent)</div><div><br></div><div> self.frame = QFrame()</div><div><br></div><div> self.vl = QVBoxLayout()</div><div> self.vtkWidget = QVTKRenderWindowInteractor(self.frame)</div><div><br></div><div> self.vl.addWidget(self.vtkWidget)</div><div><br></div><div> self.ren = vtk.vtkRenderer()</div><div> self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)</div><div> self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()</div><div><br></div><div> F = h5py.File('../realdata.h5','r')</div><div> volume = np.dstack(</div><div> (</div><div> F['02']['03']['db'],</div><div> F['02']['04']['db'],</div><div> F['02']['05']['db'],</div><div> F['02']['06']['db'],</div><div> F['02']['07']['db'],</div><div> F['02']['08']['db']</div><div> )</div><div> )</div><div> data_matrix = misc2stdimage(volume)</div><div> F.close()</div><div> m, n, p = data_matrix.shape</div><div><br></div><div> print(data_matrix.shape, data_matrix.dtype,</div><div> np.min(data_matrix), np.max(data_matrix)</div><div> )</div><div><br></div><div> v16 = vtk.vtkImageImport()</div><div> v16.CopyImportVoidPointer(data_matrix, data_matrix.nbytes) </div><div> v16.SetDataScalarTypeToUnsignedChar()</div><div> v16.SetNumberOfScalarComponents(1)</div><div> v16.SetDataExtent(0, p-1, 0, n-1, 0, m-1)</div><div> v16.SetWholeExtent(0, p-1, 0, n-1, 0, m-1)</div><div> </div><div> xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().\</div><div> GetWholeExtent(</div><div> v16.GetOutputInformation(0)</div><div> )</div><div><br></div><div> spacing = v16.GetOutput().GetSpacing()</div><div> sx, sy, sz = spacing</div><div> </div><div> origin = v16.GetOutput().GetOrigin()</div><div> ox, oy, oz = origin</div><div> </div><div> # An outline is shown for context.</div><div> outline = vtk.vtkOutlineFilter()</div><div> outline.SetInputConnection(v16.GetOutputPort())</div><div><br></div><div> outlineMapper = vtk.vtkPolyDataMapper()</div><div> outlineMapper.SetInputConnection(outline.GetOutputPort())</div><div><br></div><div> outlineActor = vtk.vtkActor()</div><div> outlineActor.SetMapper(outlineMapper)</div><div><br></div><div> # The shared picker enables us to use 3 planes at one time</div><div> # and gets the picking order right</div><div> picker = vtk.vtkCellPicker()</div><div> picker.SetTolerance(0.005)</div><div><br></div><div> norm = plt.Normalize()</div><div> colors = plt.cm.jet(norm(range(0, 255)))</div><div> colorFunc = vtk.vtkColorTransferFunction()</div><div> [colorFunc.AddRGBPoint(i, colors[i,0], colors[i,1], colors[i,2])</div><div> for i in range(0,255)]</div><div> </div><div> </div><div> # The 3 image plane widgets are used to probe the dataset.</div><div> self.planeWidgetX = vtk.vtkImagePlaneWidget()</div><div> self.planeWidgetX.DisplayTextOn()</div><div> self.planeWidgetX.SetInputConnection(v16.GetOutputPort())</div><div> self.planeWidgetX.SetPlaneOrientationToXAxes()</div><div> self.planeWidgetX.SetSliceIndex(32)</div><div> self.planeWidgetX.SetPicker(picker)</div><div> self.planeWidgetX.SetKeyPressActivationValue("x")</div><div> self.planeWidgetX.SetLookupTable(MakeLUTFromCTF(200))</div><div> </div><div> prop1 = self.planeWidgetX.GetPlaneProperty()</div><div> prop1.SetColor(1, 0, 0)</div><div><br></div><div> self.planeWidgetY = vtk.vtkImagePlaneWidget()</div><div> self.planeWidgetY.DisplayTextOn()</div><div> self.planeWidgetY.SetInputConnection(v16.GetOutputPort())</div><div> self.planeWidgetY.SetPlaneOrientationToYAxes()</div><div> self.planeWidgetY.SetSliceIndex(32)</div><div> self.planeWidgetY.SetPicker(picker)</div><div> self.planeWidgetY.SetKeyPressActivationValue("y")</div><div> self.planeWidgetY.SetLookupTable(MakeLUTFromCTF(200))</div><div> prop2 = self.planeWidgetY.GetPlaneProperty()</div><div> prop2.SetColor(1, 1, 0)</div><div> self.planeWidgetY.SetLookupTable(self.planeWidgetX.GetLookupTable())</div><div><br></div><div> self.planeWidgetZ = vtk.vtkImagePlaneWidget()<br></div><div> self.planeWidgetZ.DisplayTextOn()</div><div> self.planeWidgetZ.SetInputConnection(v16.GetOutputPort())</div><div> self.planeWidgetZ.SetPlaneOrientationToZAxes()</div><div> self.planeWidgetZ.SetSliceIndex(46)</div><div> self.planeWidgetZ.SetPicker(picker)</div><div> self.planeWidgetZ.SetKeyPressActivationValue("z")</div><div> self.planeWidgetZ.SetLookupTable(MakeLUTFromCTF(200))</div><div> prop3 = self.planeWidgetZ.GetPlaneProperty()</div><div> prop3.SetColor(0, 0, 1)</div><div> self.planeWidgetZ.SetLookupTable(self.planeWidgetX.GetLookupTable())</div><div><br></div><div> self.ren.AddActor(outlineActor)</div><div><br></div><div> self.planeWidgetX.SetInteractor(self.iren)</div><div> self.planeWidgetX.On()</div><div> self.planeWidgetY.SetInteractor(self.iren)</div><div> self.planeWidgetY.On()</div><div> self.planeWidgetZ.SetInteractor(self.iren)</div><div> self.planeWidgetZ.On()</div><div><br></div><div> self.ren.ResetCamera()<br></div><div> self.ren.ResetCameraClippingRange()</div><div> self.ren.SetViewport(0,0,1,1)</div><div> self.vtkWidget.GetRenderWindow().SetSize(400, 400)</div><div><br></div><div> self.frame.setLayout(self.vl)</div><div> self.setCentralWidget(self.frame)</div><div><br></div><div> self.show()</div><div> self.iren.Initialize()</div><div><br></div><div>if __name__ == "__main__":</div><div> </div><div> app = QApplication(sys.argv)</div><div> window = MainWindow()</div><div> myFilter = MyEventFilter(window)</div><div> app.installEventFilter(myFilter)</div><div> window.ren.ResetCamera()<br></div><div><br></div><div> sys.exit(app.exec_())</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 21, 2016 at 3:00 PM, Sankhesh Jhaveri <span dir="ltr"><<a href="mailto:sankhesh.jhaveri@kitware.com" target="_blank">sankhesh.jhaveri@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="m_1633632410952220446markdown-here-wrapper" style="font-family:Verdana,Arial,sans-serif;color:rgb(11,83,148)"><p style="margin:0px 0px 1.2em!important">Hi Michael,</p>
<p style="margin:0px 0px 1.2em!important">Depending on your use case, you could either use the vtkCamera API (or an appropriate interactor style) to zoom in on a section of the data or modify the spacing of the image data along the Z axis.</p>
<p style="margin:0px 0px 1.2em!important">Hope that helps.<br>Sankhesh</p>
<div title="MDH:SGkgTWljaGFlbCw8ZGl2Pjxicj48L2Rpdj48ZGl2PkRlcGVuZGluZyBvbiB5b3VyIHVzZSBjYXNl
LCB5b3UgY291bGQgZWl0aGVyIHVzZSB0aGUgdnRrQ2FtZXJhIEFQSSAob3IgYW4gYXBwcm9wcmlh
dGUgaW50ZXJhY3RvciBzdHlsZSkgdG8gem9vbSBpbiBvbiBhIHNlY3Rpb24gb2YgdGhlIGRhdGEg
b3IgbW9kaWZ5IHRoZSBzcGFjaW5nIG9mIHRoZSBpbWFnZSBkYXRhIGFsb25nIHRoZSBaIGF4aXMu
PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5Ib3BlIHRoYXQgaGVscHMuPC9kaXY+PGRpdj5TYW5r
aGVzaDwvZGl2Pg==" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div></div><br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Mon, Nov 21, 2016 at 4:57 AM Michael Hansen <<a href="mailto:michaelsvenna@gmail.com" target="_blank">michaelsvenna@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr" class="m_1633632410952220446gmail_msg"><span style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg">Hello. I have volumes which are of size 800x30000x6</span><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg"><br class="m_1633632410952220446gmail_msg"></div><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg">I am visualizing this using 3 vtkImagePlaneWidget.</div><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg"><br class="m_1633632410952220446gmail_msg"></div><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg">This is working ok, however when i am viewing the data in the dimension which only has columns its pretty much impossible to see the content of the 6 pixels....</div><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg">My question is... is there any way to stretch/zoom/scale the pixels in this dimension such that it becomes more visible to the viewer?</div><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg"><br class="m_1633632410952220446gmail_msg"></div><div style="font-size:12.800000190734863px" class="m_1633632410952220446gmail_msg">Thanks</div></div></div></div>
______________________________<wbr>_________________<br class="m_1633632410952220446gmail_msg">
Powered by <a href="http://www.kitware.com" rel="noreferrer" class="m_1633632410952220446gmail_msg" target="_blank">www.kitware.com</a><br class="m_1633632410952220446gmail_msg">
<br class="m_1633632410952220446gmail_msg">
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" class="m_1633632410952220446gmail_msg" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br class="m_1633632410952220446gmail_msg">
<br class="m_1633632410952220446gmail_msg">
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" class="m_1633632410952220446gmail_msg" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br class="m_1633632410952220446gmail_msg">
<br class="m_1633632410952220446gmail_msg">
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" class="m_1633632410952220446gmail_msg" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br class="m_1633632410952220446gmail_msg">
<br class="m_1633632410952220446gmail_msg">
Follow this link to subscribe/unsubscribe:<br class="m_1633632410952220446gmail_msg">
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" class="m_1633632410952220446gmail_msg" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><span class="HOEnZb"><font color="#888888"><br class="m_1633632410952220446gmail_msg">
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div class="m_1633632410952220446markdown-here-wrapper" style="font-family:'Proza Libre',sans-serif;color:rgb(0,56,107)"><h5 id="m_1633632410952220446sankhesh-jhaveri" style="color:rgb(0,65,107);margin:1.3em 0px 1em;padding:0px;font-weight:bold;font-size:1.1em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);font-weight:bold;color:rgb(11,65,148)">Sankhesh Jhaveri</h5>
<h6 id="m_1633632410952220446-sr-research-development-engineer-kitware-http-www-kitware-com-518-881-4417" style="color:rgb(0,65,107);margin:1.3em 0px 1em;padding:0px;font-weight:bold;font-size:1em;color:rgb(11,83,148);font-family:'Open Sans',sans-serif;font-weight:normal"><em>Sr. Research & Development Engineer</em> | <a href="http://www.kitware.com/" target="_blank">Kitware</a> | <a href="tel:%28518%29%20881-4417" value="+15188814417" target="_blank">(518) 881-4417</a></h6>
<div title="MDH:PGIgc3R5bGU9ImZvbnQtZmFtaWx5OiB2ZXJkYW5hLCBzYW5zLXNlcmlmOyBjb2xvcjogcmdiKDEx
LCA4MywgMTQ4KTsiPjxmb250IHNpemU9IjIiPiMjIyMjU2Fua2hlc2ggSmhhdmVyaTwvZm9udD48
L2I+PGRpdj48Zm9udCBjb2xvcj0iIzBiNTM5NCIgZmFjZT0idmVyZGFuYSwgc2Fucy1zZXJpZiIg
c2l6ZT0iMiI+PGI+PGJyPjwvYj48L2ZvbnQ+PGRpdj48c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6
IGFyaWFsLCBzYW5zLXNlcmlmOyBjb2xvcjogcmdiKDExLCA4MywgMTQ4KTsiPjxzcGFuIHN0eWxl
PSJmb250LWZhbWlseTogdmVyZGFuYSwgc2Fucy1zZXJpZjsiPjxpPiMjIyMjIypTci4gUmVzZWFy
Y2ggJmFtcDsgRGV2ZWxvcG1lbnQgRW5naW5lZXIqPC9pPiZuYnNwO3wmbmJzcDs8L3NwYW4+PC9z
cGFuPjxzcGFuIHN0eWxlPSJmb250LWZhbWlseTogdmVyZGFuYSwgc2Fucy1zZXJpZjsgY29sb3I6
IHJnYigxMSwgODMsIDE0OCk7Ij48YSBocmVmPSJodHRwOi8vd3d3LmtpdHdhcmUuY29tLyIgdGFy
Z2V0PSJfYmxhbmsiIHN0eWxlPSJjb2xvcjogcmdiKDE3LCA4NSwgMjA0KTsiPktpdHdhcmU8L2E+
Jm5ic3A7fCZuYnNwOzwvc3Bhbj48c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6IHZlcmRhbmEsIHNh
bnMtc2VyaWY7IGNvbG9yOiByZ2IoMTEsIDgzLCAxNDgpOyI+KDUxOCkgODgxLTQ0MTc8L3NwYW4+
PGJyPjwvZGl2PjxkaXY+PGRpdj48ZGl2PjxzcGFuIHN0eWxlPSJmb250LWZhbWlseTogdmVyZGFu
YSwgc2Fucy1zZXJpZjsgY29sb3I6IHJnYigxMSwgODMsIDE0OCk7Ij48L3NwYW4+PC9kaXY+PC9k
aXY+PC9kaXY+PC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div></div></div>
</font></span></blockquote></div><br></div>