<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">just as a brief attempt i tried:</div><div class=""><pre style="background-color: rgb(255, 255, 255); font-family: Menlo; font-size: 9pt;" class="">resample=sitk.ResampleImageFilter()<br class="">resample.SetReferenceImage(img)<br class="">resample.SetOutputDirection(img.GetDirection())</pre><div class="">Seems that, after I obtain the numpy array as: </div></div><div class=""><pre style="background-color: rgb(255, 255, 255); font-family: Menlo; font-size: 9pt;" class="">test=resample.Execute(img)<br class="">volume=sitk.<span style="background-color:#e4e4ff;" class="">GetArrayFromImage</span>(test)</pre><pre style="background-color: rgb(255, 255, 255); font-size: 9pt;" class=""><font face="Helvetica" class=""><span style="white-space: normal;" class="">Nothing changes in terms of data array.</span></font></pre><pre style="background-color: rgb(255, 255, 255);" class=""><font face="Helvetica" style="font-size: 9pt;" class=""><span style="white-space: normal;" class="">If I also add </span></font><span style="font-size: 9pt;" class=""><font face="Menlo" class="">resample.SetOutputSpacing(img.GetSpacing()/2.) </font><font face="Helvetica" class="">then the numpy array changes and depicts a </font></span><font face="Helvetica" class="">down-sampled<span style="font-size: 9pt;" class=""> version of the image.</span></font></pre><pre style="background-color: rgb(255, 255, 255);" class=""><span style="font-size: 9pt;" class=""><font face="Helvetica" class="">I suspect i have to use </font></span><span style="font-family: Menlo; font-size: 9pt;" class="">resample.SetTransform() </span><font face="Helvetica" class="">but I will need to create this transform using one of the transform types available in sitk. How can I create a transform that is equivalent to the one contained in the header of my MHD file? Should I create a transform starting from the volume direction and maybe offset? I could not find any example of this so far…</font></pre><pre style="background-color: rgb(255, 255, 255);" class=""><font face="Helvetica" class=""><br class=""></font></pre><pre style="background-color: rgb(255, 255, 255);" class=""><font face="Helvetica" class="">Best regards and thanks much for your help and your answers,</font></pre><pre style="background-color: rgb(255, 255, 255);" class=""><font face="Helvetica" class="">Fausto </font></pre><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 04 May 2016, at 20:40, fausto milletarì <<a href="mailto:fausto.milletari@gmail.com" class="">fausto.milletari@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello, <div class=""><br class=""><div class="">I thank you for you fast and accurate answer. This was exactly what I was looking for. Actually I don’t need to visualise the data but further process it in a common reference frame. I think that your answer solves the problem. I will look into the ResampleImageFilter (that so far I was using only to adjust the resolution of different volumes acquired with different scanners to a common one).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks a lot!</div><div class=""><br class=""></div><div class="">Fausto Milletari<br class=""><div class=""><blockquote type="cite" class=""><div class="">On 04 May 2016, at 20:36, Lowekamp, Bradley (NIH/NLM/LHC) [C] <<a href="mailto:blowekamp@mail.nih.gov" class="">blowekamp@mail.nih.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">

<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hello,
<div class=""><br class="">
</div>
<div class="">If I understand you correctly you want to rotate the image and pad it for visualization before exporting to numpy.</div>
<div class=""><br class="">
</div>
<div class="">Have you looked into the ResampleImageFilter? It accepts a transform, along with output image geometry so that you can readily manipulate the image for display. You also may want to scale the image’s intensity with a WindowLevelImageFilter for
 better visualization of the range of interest.</div>
<div class=""><br class="">
</div>
<div class="">HTH,</div>
<div class="">Brad</div>
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On May 4, 2016, at 1:14 PM, fausto milletarì <<a href="mailto:fausto.milletari@gmail.com" class="">fausto.milletari@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hello everyone,
<div class=""><br class="">
<div class="">I have a probably naive question about simpleITK. I find simpleITK extremely useful to process medical data such as MRI scans but I would like also to enjoy being able to convert my images in numpy format while respecting the transformation of
 the volume.</div>
</div>
<div class=""><br class="">
</div>
<div class="">In other words I would like to get the MRI image in numpy rotated by the correct amount around each axis with zero padding for example.</div>
<div class=""><br class="">
</div>
<div class="">when i do simply <span style="color: rgb(128, 128, 128); font-style: italic; font-family: Menlo; font-size: 9pt; background-color: rgb(255, 255, 255);" class="">sitk.GetArrayFromImage(imgResampledCropped)</span>I get back the raw data itself,
 but what I would like to do is to have a numpy array that contains the data “ready to visualise” by simple slicing of the array itself.</div>
<div class=""><br class="">
</div>
<div class="">Do you think this is doable? Is there a standard way of doing it?</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Kind regards,</div>
<div class=""><br class="">
</div>
<div class="">Fausto</div>
<div class=""><br class="">
</div>
</div>
_____________________________________<br class="">
Powered by <a href="http://www.kitware.com/" class="">www.kitware.com</a><br class="">
<br class="">
Visit other Kitware open-source projects at<br class="">
<a href="http://www.kitware.com/opensource/opensource.html" class="">http://www.kitware.com/opensource/opensource.html</a><br class="">
<br class="">
Kitware offers ITK Training Courses, for more information visit:<br class="">
<a href="http://www.kitware.com/products/protraining.php" class="">http://www.kitware.com/products/protraining.php</a><br class="">
<br class="">
Please keep messages on-topic and check the ITK FAQ at:<br class="">
<a href="http://www.itk.org/Wiki/ITK_FAQ" class="">http://www.itk.org/Wiki/ITK_FAQ</a><br class="">
<br class="">
Follow this link to subscribe/unsubscribe:<br class="">
<a href="http://public.kitware.com/mailman/listinfo/insight-users" class="">http://public.kitware.com/mailman/listinfo/insight-users</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</div>

</div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></body></html>