<div dir="ltr">Hi Fabio,<div><br></div><div>Yes, building Python extensions that depend on libraries like Cuda is muich easier with CMake build system support in scikit-build.</div><div><br></div><div>I will follow up with an example of how to set up scikit-build for ITK-based C++ code.</div><div><br></div><div>Thanks,</div><div>Matt</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 22, 2017 at 11:48 AM, D'Isidoro  Fabio <span dir="ltr"><<a href="mailto:fisidoro@ethz.ch" target="_blank">fisidoro@ethz.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you Matt,<br>
<br>
I am looking now at scikit-build.<br>
<br>
Do you think I can use it to build C++/CUDA accelerated codes that use ITK too?<br>
<br>
Is there a link to a simple example of how to setup a scikit-build for an ITK-based C++ code?<br>
<br>
Thank you,<br>
Fabio.<br>
<span class="im HOEnZb"><br>
-----Original Message-----<br>
From: Matt McCormick [mailto:<a href="mailto:matt.mccormick@kitware.com">matt.mccormick@<wbr>kitware.com</a>]<br>
Sent: Montag, 3. April 2017 20:41<br>
To: D'Isidoro Fabio <<a href="mailto:fisidoro@ethz.ch">fisidoro@ethz.ch</a>><br>
Cc: <a href="mailto:insight-users@itk.org">insight-users@itk.org</a><br>
Subject: Re: [ITK-users] ITK Python: numpy to itk image (and viceversa)<br>
<br>
</span><div class="HOEnZb"><div class="h5">Hallo Fabio,<br>
<br>
<br>
> I use ITK with Python Wrap. I need to interface my Python code with a<br>
> Cython-wrapped C++ code that takes only numpy array as input and<br>
> returns numpy array as output.<br>
<br>
Cool. By the way, you may be interested in scikit-build [1], which is a good way to build Cython-wrapped C++ code. We are using it for the ITK and SimpleITK Python packages, and it has good Cython and CMake support.<br>
<br>
<br>
> Hence, I need to convert the Python itk images into numpy array to be<br>
> given as input to the wrapped C++ code, and then convert the numpy<br>
> array in output from the wrapped C++ code back into python itk images.<br>
><br>
><br>
><br>
> Question 1) How can I do that in an efficient way? I found some posts<br>
> on itk.PyBuffer but I could not find anywhere any reference on how to<br>
> install it on my itk wrap build.<br>
<br>
Yes, itk.PyBuffer works great for that. Please review a PR for some additional documentation:<br>
<br>
  <a href="https://github.com/InsightSoftwareConsortium/ITKBridgeNumPy/pull/18" rel="noreferrer" target="_blank">https://github.com/<wbr>InsightSoftwareConsortium/<wbr>ITKBridgeNumPy/pull/18</a><br>
<br>
This has been available in ITK for a few releases as a Remote module, which can be enabled by setting<br>
<br>
  Module_BridgeNumPy=ON<br>
<br>
in ITK's CMake configuration.<br>
<br>
<br>
Since ITK 4.11.0, it is easier to build since it does not require the NumPy headers.<br>
<br>
<br>
In current ITK Git master (to be 4.12.0) the module is enabled by default.<br>
<br>
<br>
Nightly ITK Python packages for ITK Git master are now being built:<br>
<br>
  <a href="https://github.com/InsightSoftwareConsortium/ITKPythonPackage" rel="noreferrer" target="_blank">https://github.com/<wbr>InsightSoftwareConsortium/<wbr>ITKPythonPackage</a><br>
<br>
macOS and Linux are available. Windows packages will be available over the coming weeks.<br>
<br>
<br>
<br>
> Question 2) The purpose of writing a part of my algorithm in C++ is to<br>
> speed up the code. If the conversion between python itk images and<br>
> numpy arrays is slow, I would lose all the speed gain obtained with the C++ implementation.<br>
> Are there better ways to deal with that?<br>
<br>
The newer versions ITKBridgeNumPy use a NumPy array view, which does not do any copies during the conversion, and it is very fast.<br>
<br>
<br>
HTH,<br>
Matt<br>
<br>
<br>
[1] <a href="http://scikit-build.org/" rel="noreferrer" target="_blank">http://scikit-build.org/</a><br>
</div></div></blockquote></div><br></div>