[SciPy-User] 2D phase unwrapping

Christoph Gohlke cgohlke@uci....
Mon May 14 16:47:06 CDT 2012



On 5/14/2012 8:11 AM, Gregor Thalhammer wrote:
>
> Am 12.5.2012 um 11:58 schrieb Ralf Gommers:
>
>>
>>
>> On Fri, May 11, 2012 at 9:29 PM, Gregor Thalhammer
>> <gregor.thalhammer@gmail.com <mailto:gregor.thalhammer@gmail.com>> wrote:
>>
>>     Hi all,
>>
>>     I have beend searching for an implementation for phase unwrapping
>>     in 2D (and possibly also 3D). I found this old thread in the numpy
>>     mailing list
>>
>>     http://mail.scipy.org/pipermail/numpy-discussion/2008-November/038873.html
>>
>>     which mentions the C implementation from GERI:
>>     http://www.ljmu.ac.uk/GERI/90202.htm
>>
>>     While searching I found remarks by the authors that these
>>     algorithms have been incorporated into scipy, however I am unable
>>     to find them in current scipy or numpy. Am I missing something
>>     obvious?
>>     Instead I found this wrapper: https://github.com/pointtonull/pyunwrap
>>     This seems to be based on a wrapper already mentioned in the above
>>     mentioned discussion, but the links mentioned there are dead. I
>>     added some setup.py, and with some small modifications I managed
>>     to compile the extension both on OS X and Windows.
>>
>>     I would like to see these algorithms included in scipy, and I am
>>     willing to work on this.
>>
>>
>> Great!
>>
>>     So now my questions: In the old numpy-discussion thread licensing
>>     issues are raised, can anybody tell more? On the GERI homepage
>>     they distribute their code under a non-commercial-use license, but
>>     the authors seem to agree on incorporating their code into scipy.
>>     Except from this, what else would be required?
>>
>>
>> The emails about the license seem to be very clear to me, there's no
>> issue. So all it would take is someone submitting a complete wrapper
>> (with the normal requirements on docs/tests). The only things to
>> decide are then: do we want it in scipy (+1 from me), where to put it
>> and what the API should look like.
>
> Over the weekend I worked on the 2D and 3D phase unwrappers. I put a
> first version on github:
> https://github.com/geggo/phase-unwrap
> git://github.com/geggo/phase-unwrap.git
> I tested it on OS X with gcc-4.2, Python 2.7 and recent cython. (it
> crashes on Windows (MSVC 9), probably related to cython, but thats
> another story).
>
> Seems to work ok, only one basic test, no docs yet.
>
> The interface is quite simple:
>
> defunwrap(wrapped_array,
>
> wrap_around_axis_0 = False,
> wrap_around_axis_1 = False,
> wrap_around_axis_2 = False):
>
> it accepts an 2d or 3d numpy array or an masked array, and returns an
> masked array if one was given. A fresh float32 array is returned. The
> additional arguments can be used to specify cyclic boundary conditions
> along the given axis. The calculations are internally performed with
> float32. It should be quite straightforward to extend this to other
> types, but I think for the most common use cases for this algorithm
> (unwrapping of noisy data) a float32 array is sufficient.
>
> I guess a proper place in scipy would be to add this extension to
> scipy.ndimage.
>
> Please, any comments are welcome. And also some hints, why it crashes on
> Windows - or how to debug.
>
> Gregor
>

Explicitly defining the C function return types (e.g. as void) fixes the 
crash for me.

Christoph
-------------- next part --------------
diff --git a/unwrap2D/Hussein_3D_unwrapper_with_mask_and_wrap_around_option.c b/unwrap2D/Hussein_3D_unwrapper_with_mask_and_wrap_around_option.c
index e0e4cb9..08f51aa 100755
--- a/unwrap2D/Hussein_3D_unwrapper_with_mask_and_wrap_around_option.c
+++ b/unwrap2D/Hussein_3D_unwrapper_with_mask_and_wrap_around_option.c
@@ -1011,6 +1011,7 @@ void  returnVolume(VOXELM *voxel, float *unwrappedVolume, int volume_width, int
 }
 
 //the main function of the unwrapper
+void
 unwrap3D(float* wrapped_volume, float* unwrapped_volume, unsigned char* input_mask,
 	 int volume_width, int volume_height, int volume_depth,
 	 int wrap_around_x, int wrap_around_y, int wrap_around_z)
diff --git a/unwrap2D/Miguel_2D_unwrapper_with_mask_and_wrap_around_option.c b/unwrap2D/Miguel_2D_unwrapper_with_mask_and_wrap_around_option.c
index 3017c52..2e851eb 100755
--- a/unwrap2D/Miguel_2D_unwrapper_with_mask_and_wrap_around_option.c
+++ b/unwrap2D/Miguel_2D_unwrapper_with_mask_and_wrap_around_option.c
@@ -680,6 +680,7 @@ void  returnImage(PIXELM *pixel, float *unwrapped_image, int image_width, int im
 }
 
 //the main function of the unwrapper
+void
 unwrap2D(float* wrapped_image, float* UnwrappedImage, unsigned char* input_mask, 
 	 int image_width, int image_height, 
 	 int wrap_around_x, int wrap_around_y)
diff --git a/unwrap2D/unwrap2D.pyx b/unwrap2D/unwrap2D.pyx
index 9bd901d..dab5216 100755
--- a/unwrap2D/unwrap2D.pyx
+++ b/unwrap2D/unwrap2D.pyx
@@ -1,4 +1,4 @@
-cdef extern unwrap2D(float* wrapped_image, 
+cdef extern void unwrap2D(float* wrapped_image, 
                      float* unwrapped_image, 
                      unsigned char* input_mask, 
                      int image_width, int image_height,
diff --git a/unwrap2D/unwrap3D.pyx b/unwrap2D/unwrap3D.pyx
index 7a0aee9..aa18b37 100644
--- a/unwrap2D/unwrap3D.pyx
+++ b/unwrap2D/unwrap3D.pyx
@@ -1,4 +1,4 @@
-cdef extern unwrap3D(float* wrapped_volume, 
+cdef extern void unwrap3D(float* wrapped_volume, 
                      float* unwrapped_volume, 
                      unsigned char* input_mask, 
                      int image_width, int image_height, int volume_depth,


More information about the SciPy-User mailing list