Not sure if this is related but try setting the spacing and orientation after you allocate the image. <br><br>Cagatay <div><br><div class="gmail_quote">On Wed, Oct 24, 2012 at 3:06 PM, Wolfram Timm <span dir="ltr">&lt;<a href="mailto:comail@mac.com" target="_blank">comail@mac.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I don&#39;t get the background of this problem:<br>
<br>
Inside a DLL I am trying to create a 3D ITK image of type unsigned short. This works (filewriter successful), when spacing is 1.0 for each dimension. Inside the DLL I get an Access Violation even preventing throwing the exception when choosing a different spacing like 0.2, 0.2, 2.0 (yes, awful anisotropy). This is independent of the use of ITKImportFilter or creating just an ITK image.<br>

<br>
Here&#39;s the relevant code (afaik):<br>
<br>
typedef unsigned short PixelType;<br>
typedef itk::Image&lt; PixelType, 3 &gt; ImageType;<br>
<br>
  ImageType::Pointer img = ImageType::New();<br>
<br>
  ImageType::SizeType size;<br>
  size[0] = 512;<br>
  size[1] = 512;<br>
  size[2] = 86;<br>
<br>
  ImageType::IndexType start;<br>
  start.Fill(0);<br>
<br>
  ImageType::RegionType region;<br>
  region.SetIndex(start);<br>
  region.SetSize(size);<br>
<br>
  img-&gt;SetRegions(region);<br>
<br>
  double origin[3];<br>
  origin[0] = 0.0;<br>
  origin[1] = 0.0;<br>
  origin[2] = 0.0;<br>
  img-&gt;SetOrigin(origin);<br>
<br>
  ImportImageFilterType::SpacingType spacing;<br>
  spacing[0] = 0.2;<br>
  spacing[1] = 0.2;<br>
  spacing[2] = 2.0;<br>
  img-&gt;SetSpacing(spacing);<br>
<br>
  try<br>
      {<br>
      log(&quot;img pre Allocate()&quot;);<br>
      img-&gt;Allocate();<br>
      log(&quot;img pos Allocate()&quot;);<br>
  }<br>
  catch( itk::ExceptionObject &amp; exp )<br>
  {<br>
      log(&quot;Exception caught !&quot;);<br>
      log((string)exp.GetDescription());<br>
  }<br>
<br>
  WriterType::Pointer writer = WriterType::New();<br>
<br>
  writer-&gt;SetFileName(&quot;d:\\temp\\i.tif&quot;);<br>
<br>
  writer-&gt;SetInput(img);<br>
<br>
  try<br>
  {<br>
      writer-&gt;Update();<br>
  }<br>
  catch( itk::ExceptionObject &amp; exp )<br>
  {<br>
      log(&quot;Exception caught !&quot;);<br>
      log((string)exp.GetDescription());<br>
  }<br>
<br>
<br>
Any help really is appreciated, since I don&#39;t get the problem here.<br>
<br>
Thanks.<br>
Wolfram<br>
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Cemal Cagatay Bilgin</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Life Sciences Division</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Lawrence Berkeley National Lab</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">MS977, One Cyclotron Road</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Berkeley, CA 94720, USA</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Email: ccbilgin</span><a href="mailto:hchang@lbl.gov" style="color:rgb(17,85,204);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)" target="_blank">@lbl.gov</a><br>

</div>