unwrap: moved pure python code from unwrap2D.pyx to unwrap.py, allocate output array in pure python

This commit is contained in:
Gregor Thalhammer
2012-05-13 18:44:53 +02:00
committed by Jostein Bø Fløystad
parent c61ae90a4d
commit 3d4fb9559c
4 changed files with 25 additions and 25 deletions
-1
View File
@@ -7,7 +7,6 @@ import numpy as np
ext_modules = [
Extension('unwrap2D',
['unwrap2D.pyx',
#'Miguel_2D_unwrapper_with_mask_and_wrap_around_option.cpp',
'Miguel_2D_unwrapper_with_mask_and_wrap_around_option.c',
],
include_dirs = [np.get_include(),],
+1 -1
View File
@@ -1,5 +1,5 @@
from numpy.testing import *
from unwrap2D import unwrap2D
from unwrap import unwrap2D
import numpy as np
from numpy import outer, arange, ones, abs, empty, power, indices
+20
View File
@@ -0,0 +1,20 @@
import numpy as np
from unwrap2D import _unwrap2D
def unwrap2D(wrapped_array, wrap_around_x = False, wrap_around_y = False):
wrapped_array = np.require(wrapped_array, np.float32, ['C'])
wrapped_array_masked = np.ma.asarray(wrapped_array)
unwrapped_array = np.empty_like(wrapped_array_masked.data)
_unwrap2D(wrapped_array_masked.data,
np.ma.getmaskarray(wrapped_array_masked).astype(np.uint8),
unwrapped_array,
wrap_around_x, wrap_around_y)
if np.ma.isMaskedArray(wrapped_array):
return np.ma.array(unwrapped_array, mask = wrapped_array_masked.mask)
else:
return unwrapped_array
#TODO: set_fill to minimum value
#TODO: check for empty mask, not a single contiguous pixel
+4 -23
View File
@@ -1,41 +1,22 @@
import numpy as np
cimport numpy as np
import numpy.ma
#import numpy as np
#cimport numpy as np
cdef extern int unwrap(float* wrapped_image,
float* unwrapped_image,
unsigned char* input_mask,
int image_width, int image_height,
int wrap_around_x, int wrap_around_y)
def unwrap2D(input, wrap_around_x = False, wrap_around_y = False):
masked_array = numpy.ma.asarray(input, dtype = np.float32)
unwrapped_array = _unwrap2D(masked_array.data,
numpy.ma.getmaskarray(masked_array).astype(np.uint8),
wrap_around_x, wrap_around_y)
if numpy.ma.isarray(input):
return numpy.ma.array(unwrapped_array, mask = input.mask)
else:
return unwrapped_array
#TODO: set_fill to minimum value
cdef _unwrap2D(float[:,::1] array,
def _unwrap2D(float[:,::1] array,
unsigned char[:,::1] mask,
float[:,::1] unwrapped_array,
wrap_around_x, wrap_around_y):
cdef float[:,::1] unwrapped_array = np.empty_like(array)
cdef int h = array.shape[0]
cdef int w = array.shape[1]
#TODO: check for masked array/
unwrap(&array[0,0],
&unwrapped_array[0,0],
&mask[0,0],
array.shape[0], array.shape[1],
wrap_around_x, wrap_around_y,
)
return np.asarray(unwrapped_array)