I believe you need to look at the vtkImageReader2 code, and do soemthing like the following:<br>
<br>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">reader = vtk.vtkTIFFReader()<br>
reader.SetFileDimensionality(3)<br>
reader.SetFilePrefix("D:/TestStack")<br>
reader.SetFilePattern("%s%04i.tiff");<br>
reader.SetDataExtent(0, xdim-1, 0, ydim-1, 0, numslices-1);<br>
Use SetFileNameSliceOffset and SetFileNameSliceSpacing if necessary.<br>
</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">I've found that GetScalarRange function to be rather unreliable. I find it alot more accurate to use:<br>
reader.GetOutput().GetPointData().GetArray(0).GetRange()<br>
but make sure to call reader.Update() first.<br>
</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><br>
</span></font></p>
<br><br><div><span class="gmail_quote">On 6/8/05, <b class="gmail_sendername">James Carroll</b> <<a href="mailto:jim@microbrightfield.com">jim@microbrightfield.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Hi,</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">I'm trying to do an image stack conversion from a
16bit TIFF with 50 different (multi-tiff style) z planes in it to an 8 bit
TIFF, and I'll want to do some math as a filter in-between.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">How can I have it read, filter and write an entire
volume? The SetFileDimensionality(3) doesn't seem to pick up the
different images in the multi-tiff.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">The weired part is that the format is 16 bit unsigned
integer, but vtk GetScalarRange() gives 3.0 to 11.0 which is really
narrow, and floating point? I know there are more than 8 different pixel
intensities.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">tiffinfo gives me the following information:</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">TIFF Directory at offset 0xfaa</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Subfile Type: (0 = 0x0)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Image Width: 1360 Image Length: 1036</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Resolution: 72, 72 pixels/inch</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Bits/Sample: 16</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Sample Format: unsigned integer</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Compression Scheme: None</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Photometric Interpretation: min-is-black</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Samples/Pixel: 1</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Rows/Strip: 1036</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Planar Configuration: single image plane</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Here's my best guess so far, </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">import vtk</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">reader = vtk.vtkTIFFReader()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">reader.SetFileDimensionality(3)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">reader.SetFileName("D:/TestStack.tiff")</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># iterate over the entire stack, and see what the min/max of
the pixel</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># values really is</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">reader.Update()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">minmax = reader.GetOutput().GetScalarRange()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">print "The pixel values fall between", minmax</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># this prints float 3.0 to 11.0</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># I'm confused why an unsigned integer tiff gives a float
scalar</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># range, if it's really integer 3 - 11 that's too narrow a
dynamic range.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">bounds = reader.GetOutput().GetBounds()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">print "The Bounds are", bounds</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># prints (0.0, 1359.0, 0.0, 1035.0, 0.0, 0.0)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># I'd expect the z bounds to be 0.0 to 49.0</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># eventually…</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">#scale = vtk.vtkImageShiftScale()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># shift all the 16 bit pixels eight bits to the left</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">#scale.SetScale(256.0) </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">#scale.</span></font>SetOutputScalarTypeToChar (
) <font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"></span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># write an 8 bit grayscale tiff stack for the entire volume</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">writer = vtk.vtkTIFFWriter()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">writer.SetFileName("<a>D://wood.tiff</a>")</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">writer.SetInput(reader.GetOutput())</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">writer.Write()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"># only one plane gets written, and it's totally black</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Thanks for the help!</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">-Jim</span></font></p>
</div>
<br>_______________________________________________<br>This is the private VTK discussion list.<br>Please keep messages on-topic. Check the FAQ at: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to subscribe/unsubscribe:<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers
</a><br><br><br></blockquote></div><br><br><br>-- <br>Randall Hand<br><a href="http://www.yeraze.com">http://www.yeraze.com</a>