<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>Re: [vtkusers] read Analyze files with VTK</TITLE>
</HEAD>
<BODY>
<DIV id=idOWAReplyText56351 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Hallo Tron,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>I am currently coding java so I wrote my
own routines, based on the following PDF documentation: <A
href="http://www.mayo.edu/bir/PDF/ANALYZE75.pdf">http://www.mayo.edu/bir/PDF/ANALYZE75.pdf</A></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>It's quick & dirty but does the job
well I guess. Mail me if you want the source.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Thanks for the help,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Wouter</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>Van:</B> vtkusers-bounces@vtk.org namens Tron
Darvann<BR><B>Verzonden:</B> do 4/21/2005 11:17<BR><B>Aan:</B> vtkusers@vtk.org;
Cuypers Wouter<BR><B>Onderwerp:</B> Re: [vtkusers] read Analyze files with
VTK<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Hello Wouter,<BR>I use vtkImageReader which can read a single
.img Analyze file, and is not restricted to 16 bit data.<BR>The way I read the
header information in the .hdr file is not optimal. Maybe you can solve
this more<BR>elegantly. Here below is my ReadAnalyzeImage tcl
procedure.<BR>Tron Darvann<BR><BR>proc ReadAnalyzeImage {infilename} {<BR>
# NOTE: This routine can presently only read Analyze headers written in
native<BR> # format, i.e. on the same type of machine as we now try to
read it. This is due<BR> # to the tcl command binary scan that
cannot read floating point values unless native.<BR> global xpix ypix zpix
xs ys zs<BR> source vtkImageInclude.tcl<BR> set indir [file rootname
$infilename]<BR> set img_extension ".img"<BR> set imgname
$indir$img_extension<BR> imreader Delete<BR> vtkImageReader
imreader<BR> # Get info from Analyze header<BR> set fileId [open
$infilename r]<BR> set var [read $fileId 4]<BR> binary scan $var i
hsize<BR><BR> if { $hsize == 348 } {<BR> # We read the
long integer 348 correctly. Is written on native
machine.<BR> set native
1 <BR> } else
{<BR> # We did not read the long integer 348 correctly.
Possibly written on other machine.<BR> # Try to read it
again.<BR> close $fileId<BR> set fileId
[open $infilename r]<BR> set var [read $fileId
4]<BR> binary scan $var I hsize<BR> if {
$hsize == 348 } {<BR> # We read the long integer
348 correctly. Is written on another
machine.<BR> set native 0<BR> }
else {<BR> # We did not read the long integer 348
correctly. Not Analyze format.<BR>
notify_error "Could not read file header. Possibly corrupt or non-Analyze
format"<BR> return<BR>
} <BR>
}<BR> if { $native == 0 } {<BR> notify_error "Analyze
file must be in native format. Try .hea or convert to
native."<BR> return -1<BR> #set var [read
$fileId 28]<BR> #set var [read $fileId
4]<BR> #binary scan $var I extent<BR> #set
var [read $fileId 4]<BR> #set var [read $fileId
2]<BR> #binary scan $var S ndims<BR> #set
var [read $fileId 2]<BR> #binary scan $var S
xs<BR> #notify $xs xs<BR> #set var [read
$fileId 2]<BR> #binary scan $var S ys<BR>
#set var [read $fileId 2]<BR> #binary scan $var S
zs<BR> #set var [read $fileId 22]<BR> #set
var [read $fileId 2]<BR> #binary scan $var S
datatype<BR> #set var [read $fileId 2]<BR>
#binary scan $var S bitpix<BR> #set var [read $fileId
2]<BR> #set var [read $fileId 4]<BR> #set
var [read $fileId 4]<BR> #binary scan $var f
xpix<BR> #set var [read $fileId 4]<BR>
#binary scan $var f ypix<BR> #set var [read $fileId
4]<BR> #binary scan $var f zpix<BR> #set
xpix 1.0<BR> #set ypix 1.0<BR> #set zpix
1.0<BR> #imreader
SetDataByteOrderToBigEndian<BR> #EditHeader<BR> } else
{<BR> # Is in native format.<BR> set var
[read $fileId 28]<BR> set var [read $fileId
4]<BR> binary scan $var i extent<BR> set var
[read $fileId 4]<BR> set var [read $fileId
2]<BR> binary scan $var s ndims<BR> set var
[read $fileId 2]<BR> binary scan $var s
xs<BR> set var [read $fileId 2]<BR> binary
scan $var s ys<BR> set var [read $fileId
2]<BR> binary scan $var s zs<BR> set var
[read $fileId 22]<BR> set var [read $fileId
2]<BR> binary scan $var s datatype<BR> set
var [read $fileId 2]<BR> binary scan $var s
bitpix<BR> set var [read $fileId 2]<BR> set
var [read $fileId 4]<BR> set var [read $fileId
4]<BR> binary scan $var f xpix<BR> set var
[read $fileId 4]<BR> binary scan $var f
ypix<BR> set var [read $fileId 4]<BR> binary
scan $var f zpix<BR> }<BR> if {($bitpix != 8) &&
($bitpix != 16) } {<BR> notify_error "Sorry, image
must be 8 or 16 bit in current landmarker implementation."<BR>
}<BR> close $fileId<BR> set hx [expr $xs - 1 ]<BR> set hy
[expr $ys - 1 ]<BR> set hz [expr $zs - 1 ]<BR> imreader
SetDataByteOrderToLittleEndian<BR> imreader SetFileDimensionality
3<BR> imreader SetDataExtent 0 $hx 0 $hy 0 $hz<BR> imreader
SetDataSpacing $xpix $ypix $zpix<BR> imreader SetFileName
$imgname<BR> imreader SetHeaderSize 0<BR> if {$bitpix == 16}
{<BR> imreader SetDataScalarTypeToShort<BR> }<BR>
if {$bitpix == 8} {<BR> imreader
SetDataScalarTypeToUnsignedChar<BR> }<BR><BR> #imreader SetDataMask
0x7fff<BR> #reader DebugOn<BR> #reader Update<BR><BR> # We set
as default that image is to be flipped in y (needed to fit with Mvox)<BR>
set ImageFlipY 1<BR> <BR> if {$ImageFlipY == 1} {<BR> # Flip
volume in y<BR> <BR> vtkImageFlip reslice1<BR>
reslice1 SetInput [imreader GetOutput]<BR> reslice1
SetFilteredAxis 1<BR> }<BR><BR><BR> viewer Delete<BR>
vtkImageViewer viewer<BR> viewer SetInput [imreader GetOutput]<BR>
viewer SetZSlice 0<BR> #viewer SetColorWindow 2000<BR> #viewer
SetColorLevel 1000<BR> #viewer DebugOn<BR> #viewer
Render<BR><BR> viewer SetPosition 50 50<BR><BR> #make
interface<BR> source
ImageViewerInterface.tcl<BR><BR>}<BR>_______________________________________________<BR>This
is the private VTK discussion list.<BR>Please keep messages on-topic. Check the
FAQ at: <A
href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</A><BR>Follow
this link to subscribe/unsubscribe:<BR><A
href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</A><BR></FONT></P></DIV>
</BODY>
</HTML>