<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">I would indeed try
      nilearn.image.resample_img()<br>
      B<br>
      On 18/08/2017 23:28, Christopher Markiewicz wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAHE-diPuMtMPTenHi-Oq+r8E_SgPDq0W8CAP_mRMJmbG8-Dgng@mail.gmail.com">
      <div dir="ltr">
        <div>Hi Michael,</div>
        <div><br>
        </div>
        At first glance this looks reasonable to me, so if I were to try
        to figure out the issue, I'd probably end up digging through
        nilearn's image resampling, which uses ndimage.affine_transform
        under the hood [0]. It's a much more flexible function that what
        you're looking for, but I think you should be able to find what
        you need in all of that.
        <div><br>
        </div>
        <div>I'm also pretty sure that, with a nipy image, you can do
          this with `img[::2, ::2, ::2]`, but not sure quite where to
          point you to in that codebase.<br>
          <div><br>
          </div>
          <div>Chris</div>
          <div><br>
          </div>
          <div>[0] <a
href="https://github.com/nilearn/nilearn/blob/master/nilearn/image/resampling.py#L221-L271"
              moz-do-not-send="true">https://github.com/nilearn/nilearn/blob/master/nilearn/image/resampling.py#L221-L271</a></div>
        </div>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Fri, Aug 18, 2017 at 4:52 PM,
            Michael Waskom <span dir="ltr"><<a
                href="mailto:mwaskom@nyu.edu" target="_blank"
                moz-do-not-send="true">mwaskom@nyu.edu</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div dir="ltr">Hi Matthew/Chris/others,
                <div><br>
                </div>
                <div>Building on my previous question, I would also like
                  to implement a pure-python downsampling of my images.
                  I have done:</div>
                <div><br>
                </div>
                <div><font face="monospace, monospace">import nibabel as
                    nib</font></div>
                <div><font face="monospace, monospace">from scipy import
                    ndimage</font></div>
                <div><font face="monospace, monospace">img =
                    nib.load("brain.nii")</font></div>
                <div><font face="monospace, monospace">data =
                    img.get_data()</font></div>
                <div><font face="monospace, monospace">lowres_data =
                    ndimage.zoom(data, .5)</font></div>
                <div><font face="monospace, monospace">zoom_xfm =
                    np.eye(4)</font></div>
                <div><font face="monospace, monospace">zoom_xfm[:3, :3]
                    /= .5</font></div>
                <div><span style="font-family:monospace,monospace">lowres_affine
                    = img.affine.dot(zoom_xfm)</span><br>
                </div>
                <div><font face="monospace, monospace">lowres_img =
                    nib.Nifti1Image(lowres_data, lowres_affine,
                    img.header)</font></div>
                <div><font face="monospace, monospace">lowres_img.to_fileame("lowres_<wbr>brain.nii")</font></div>
                <div><font face="monospace, monospace"><br>
                  </font></div>
                <div>This is very close, but when I view the resulting
                  image in Freeview (my downsampled image is also
                  slightly stretched relative to the anatomical).</div>
                <div><br>
                </div>
                <div>I can also compare to the result from mri_convert,
                  i.e. <font face="monospace, monospace">mri_convert
                    brain.nii -vs 2 2 2 lowres_brain.nii. </font>The
                  resulting image is not stretched relative to the hires
                  brain, so it's not an artifact on Freeview's side. The
                  images also don't have an identical affine (it is off
                  by 0.5 in the third row of the final column.</div>
                <div><br>
                </div>
                <div>What am I missing about how to alter to affine of a
                  downsampled image? Alternative, is ndimage.zoom not
                  the right Python function to use here?</div>
                <div><br>
                </div>
                <div>Best,</div>
                <div>Michael</div>
              </div>
              <br>
              ______________________________<wbr>_________________<br>
              Neuroimaging mailing list<br>
              <a href="mailto:Neuroimaging@python.org"
                moz-do-not-send="true">Neuroimaging@python.org</a><br>
              <a
                href="https://mail.python.org/mailman/listinfo/neuroimaging"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://mail.python.org/<wbr>mailman/listinfo/neuroimaging</a><br>
              <br>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Neuroimaging mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Neuroimaging@python.org">Neuroimaging@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/neuroimaging">https://mail.python.org/mailman/listinfo/neuroimaging</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>