<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi ITK users,&nbsp;</div><div><br></div><div>I am using ITK to read some Analyze files. I use the itkAnalyzeImageIO class to do so.</div><div>Until now, I was always reading the image as double, because I though all data types</div><div>can be represented by double.</div><div><br></div><div>However, this has a cost in memory. Some of my images are 8 bits, so I do not want to</div><div>use 8 times the memory needed. So once the image is loaded, I check the component type,</div><div>and then cast my image into that type with success.</div><div><br></div><div>I then realise that ReadFileInformation could be use to get the scalar type before the image is</div><div>read, so I use read the image in its scalar type directly. However, that change caused some files</div><div>that were supported before to crash my application.</div><div><br></div><div>Here is the code that reads my image. The scalar type is UCHAR, and that is the type found by</div><div>ReadImageInformation as well. The following code works fine when the templated scalar type</div><div>is double, but crashes when the type is uint8 (See code below).</div><div><br></div><div>Am I missing something here?</div><div><br></div><div>The code and backtrace are at the end of the mail. I tried that code with the latest ITK release, and ITK CVS.</div><div>I built ITK on MAC OSX 10.5.6 (intel).</div><div><br></div><div>Thanks,</div><div><br></div><div>Mathieu</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">int</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> main (</font></font><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">int</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> argc, </font></font><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">char</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> *argv[])</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">{</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">(</font></font><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">void</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">)argc;</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">(</font></font><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">void</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">)argv;</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; min-height: 16px; "><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"><br></font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span style=""><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">// Open the file with the ITK reader.</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span style=""><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">// Create the image reader.</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">typedef</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> itk::Image&lt;uint8_t, 3> ITK3DImage;</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">typedef</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> itk::ImageFileReader&lt;ITK3DImage> ITK3DReader;</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">ITK3DReader::Pointer reader = ITK3DReader::New();</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">reader->SetFileName("/Volumes/Data/DATA/Analyse/espagnol_15_1_20061128_095602_1_mri_byte.hdr");</font></font></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px"><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"><br class="webkit-block-placeholder"></font></font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span style=""><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">// Create and set the Image IO type.</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">itk::AnalyzeImageIO::Pointer imageIO = itk::AnalyzeImageIO::New();</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">reader->SetImageIO(imageIO);</font></font></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px"><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"><br class="webkit-block-placeholder"></font></font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span style=""><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">try</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">{</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">                </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">reader->Update();&nbsp; </font></font><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">// CRASH</font></font></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">}</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">catch</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> (...)</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">{</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">}</font></font></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px"><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"><br class="webkit-block-placeholder"></font></font></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">ITK3DImage::Pointer image = reader->GetOutput();</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">        </font></font></span><span style=""><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">assert</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"> (image);</font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; min-height: 16px; "><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica"><br></font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">&nbsp; &nbsp; </font></font><span style="color: #1046da"><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica">re</font></font><font class="Apple-style-span" face="Helvetica">turn</font></span><font class="Apple-style-span" face="Helvetica"> 0;</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">}</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">The backtrace is:</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">#0 0xffe008c7 in ??</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">0000001 0x5fbfc7a0 in ??</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">0000002 0x81620192 in fread</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">0000003 0x81620192 in fread</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">0000004 0x812fc3ed in gzread</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">0000005 0x0044d528 in itk::AnalyzeImageIO::Read at itkAnalyzeImageIO.cxx:728</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "><font class="Apple-style-span" face="Helvetica">0000006 0x000dfd61 in itk::ImageFileReader&lt;itk::Image&lt;unsigned char, 3u>, itk::DefaultConvertPixelTraits&lt;unsigned char> >::GenerateData at itkImageFileReader.txx:398</font></div></font></div></div><br><div> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>____________________&nbsp;<br>Mathieu Coursolle, M.Ing.<span class="Apple-tab-span" style="white-space: pre; ">                </span><br>Rogue Research Inc. &nbsp; &nbsp; &nbsp; &nbsp;</div><div><a href="http://www.rogue-research.com/">www.rogue-research.com</a><br></div><div><br></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br></body></html>