[vtkusers] Image volume conversion

Randall Hand randall.hand at gmail.com
Wed Jun 8 14:13:31 EDT 2005


I believe you need to look at the vtkImageReader2 code, and do soemthing 
like the following:

reader = vtk.vtkTIFFReader()
reader.SetFileDimensionality(3)
reader.SetFilePrefix("D:/TestStack")
reader.SetFilePattern("%s%04i.tiff");
reader.SetDataExtent(0, xdim-1, 0, ydim-1, 0, numslices-1);
Use SetFileNameSliceOffset and SetFileNameSliceSpacing if necessary.
 
I've found that GetScalarRange function to be rather unreliable. I find it 
alot more accurate to use:
reader.GetOutput().GetPointData().GetArray(0).GetRange()
but make sure to call reader.Update() first.
 

 

On 6/8/05, James Carroll <jim at microbrightfield.com> wrote:
> 
>   Hi,
> 
>  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.
> 
>  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.
> 
>  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.
> 
>  tiffinfo gives me the following information:
> 
> TIFF Directory at offset 0xfaa
> 
> Subfile Type: (0 = 0x0)
> 
> Image Width: 1360 Image Length: 1036
> 
> Resolution: 72, 72 pixels/inch
> 
> Bits/Sample: 16
> 
> Sample Format: unsigned integer
> 
> Compression Scheme: None
> 
> Photometric Interpretation: min-is-black
> 
> Samples/Pixel: 1
> 
> Rows/Strip: 1036
> 
> Planar Configuration: single image plane
> 
>  Here's my best guess so far, 
> 
>  import vtk
> 
>  reader = vtk.vtkTIFFReader()
> 
> reader.SetFileDimensionality(3)
> 
> reader.SetFileName("D:/TestStack.tiff")
> 
>  # iterate over the entire stack, and see what the min/max of the pixel
> 
> # values really is
> 
> reader.Update()
> 
> minmax = reader.GetOutput().GetScalarRange()
> 
> print "The pixel values fall between", minmax
> 
> # this prints float 3.0 to 11.0
> 
> # I'm confused why an unsigned integer tiff gives a float scalar
> 
> # range, if it's really integer 3 - 11 that's too narrow a dynamic range.
> 
>  bounds = reader.GetOutput().GetBounds()
> 
> print "The Bounds are", bounds
> 
> # prints (0.0, 1359.0, 0.0, 1035.0, 0.0, 0.0)
> 
> # I'd expect the z bounds to be 0.0 to 49.0
> 
>  # eventually…
> 
> #scale = vtk.vtkImageShiftScale()
> 
> # shift all the 16 bit pixels eight bits to the left
> 
> #scale.SetScale(256.0) 
> 
> #scale.SetOutputScalarTypeToChar ( ) 
> 
>   # write an 8 bit grayscale tiff stack for the entire volume
> 
> writer = vtk.vtkTIFFWriter()
> 
> writer.SetFileName("D://wood.tiff")
> 
>  writer.SetInput(reader.GetOutput())
> 
> writer.Write()
> 
> # only one plane gets written, and it's totally black
> 
>  Thanks for the help!
> 
> -Jim
>  
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: 
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 
> 


-- 
Randall Hand
http://www.yeraze.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050608/d16f0384/attachment.htm>


More information about the vtkusers mailing list