mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-21 12:50:27 +08:00
wrapped 7 more functions
new functions: cvSobel cvLaplace cvCanny cvPreCornerDetect cvCornerEigenValsAndVecs cvCornerMinEigenVal cvCornerHarris
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,9 @@ cdef int assert_ndims(np.ndarray arr, dims) except -1
|
||||
cdef int assert_nchannels(np.ndarray arr, channels) except -1
|
||||
cdef int assert_same_dtype(np.ndarray arr1, np.ndarray arr2) except -1
|
||||
cdef int assert_same_shape(np.ndarray arr1, np.ndarray arr2) except -1
|
||||
cdef int assert_same_width_and_height(np.ndarray arr1, np.ndarray arr2) except -1
|
||||
cdef int assert_like(np.ndarray arr1, np.ndarray arr2) except -1
|
||||
cdef int assert_not_sharing_data(np.ndarray arr1, np.ndarray arr2) except -1
|
||||
cdef np.ndarray new_array(int ndim, np.npy_intp* shape, dtype)
|
||||
cdef np.ndarray new_array_like(np.ndarray arr)
|
||||
cdef np.ndarray new_array_like_diff_dtype(np.ndarray arr, dtype)
|
||||
@@ -120,12 +120,30 @@ cdef int assert_same_shape(np.ndarray arr1, np.ndarray arr2) except -1:
|
||||
if not np.PyArray_SAMESHAPE(arr1, arr2):
|
||||
raise ValueError('arrays not same shape')
|
||||
return 1
|
||||
|
||||
cdef int assert_same_width_and_height(np.ndarray arr1, np.ndarray arr2) except -1:
|
||||
cdef np.npy_intp* shape1 = arr1.shape
|
||||
cdef np.npy_intp* shape2 = arr2.shape
|
||||
if (shape1[0] != shape2[0]) or (shape1[1] != shape2[1]):
|
||||
raise ValueError('Arrays must have same width and height')
|
||||
return 1
|
||||
|
||||
cdef int assert_like(np.ndarray arr1, np.ndarray arr2) except -1:
|
||||
assert_same_dtype(arr1, arr2)
|
||||
assert_same_shape(arr1, arr2)
|
||||
return 1
|
||||
|
||||
cdef int assert_not_sharing_data(np.ndarray arr1, np.ndarray arr2) except -1:
|
||||
if arr1.data == arr2.data:
|
||||
raise ValueError('In place operation not supported. Make sure \
|
||||
the out array is not just a view of src array')
|
||||
return 1
|
||||
|
||||
cdef np.ndarray new_array(int ndim, np.npy_intp* shape, dtype):
|
||||
# need to incref because numpy will apprently steal a dtype reference
|
||||
Py_INCREF(<object>dtype)
|
||||
return PyArray_Empty(ndim, shape, dtype, 0)
|
||||
|
||||
cdef np.ndarray new_array_like(np.ndarray arr):
|
||||
# need to incref because numpy will apprently steal a dtype reference
|
||||
Py_INCREF(<object>arr.dtype)
|
||||
|
||||
+2865
-240
File diff suppressed because it is too large
Load Diff
@@ -20,11 +20,6 @@ except:
|
||||
# opencv function declarations
|
||||
###################################
|
||||
|
||||
# cvSmooth
|
||||
ctypedef void (*cvSmoothPtr)(IplImage*, IplImage*, int, int, int, double, double)
|
||||
cdef cvSmoothPtr c_cvSmooth
|
||||
c_cvSmooth = (<cvSmoothPtr*><size_t>ctypes.addressof(cv.cvSmooth))[0]
|
||||
|
||||
# cvSobel
|
||||
ctypedef void (*cvSobelPtr)(IplImage*, IplImage*, int, int, int)
|
||||
cdef cvSobelPtr c_cvSobel
|
||||
@@ -40,15 +35,235 @@ ctypedef void (*cvCannyPtr)(IplImage*, IplImage*, double, double, int)
|
||||
cdef cvCannyPtr c_cvCanny
|
||||
c_cvCanny = (<cvCannyPtr*><size_t>ctypes.addressof(cv.cvCanny))[0]
|
||||
|
||||
|
||||
# cvPreCornerDetect
|
||||
ctypedef void (*cvPreCorneDetectPtr)(IplImage*, IplImage*, int)
|
||||
cdef cvPreCorneDetectPtr c_cvPreCornerDetect
|
||||
c_cvPreCornerDetect = (<cvPreCorneDetectPtr*><size_t>ctypes.addressof(cv.cvPreCornerDetect))[0]
|
||||
|
||||
# cvCornerEigenValsAndVecs
|
||||
ctypedef void (*cvCornerEigenValsAndVecsPtr)(IplImage*, IplImage*, int, int)
|
||||
cdef cvCornerEigenValsAndVecsPtr c_cvCornerEigenValsAndVecs
|
||||
c_cvCornerEigenValsAndVecs = (<cvCornerEigenValsAndVecsPtr*><size_t>ctypes.addressof(cv.cvCornerEigenValsAndVecs))[0]
|
||||
|
||||
# cvCornerMinEigenVal
|
||||
ctypedef void (*cvCornerMinEigenValPtr)(IplImage*, IplImage*, int, int)
|
||||
cdef cvCornerMinEigenValPtr c_cvCornerMinEigenVal
|
||||
c_cvCornerMinEigenVal = (<cvCornerMinEigenValPtr*><size_t>ctypes.addressof(cv.cvCornerMinEigenVal))[0]
|
||||
|
||||
# cvCornerHarris
|
||||
ctypedef void (*cvCornerHarrisPtr)(IplImage*, IplImage*, int, int, double)
|
||||
cdef cvCornerHarrisPtr c_cvCornerHarris
|
||||
c_cvCornerHarris = (<cvCornerHarrisPtr*><size_t>ctypes.addressof(cv.cvCornerHarris))[0]
|
||||
|
||||
# cvSmooth
|
||||
ctypedef void (*cvSmoothPtr)(IplImage*, IplImage*, int, int, int, double, double)
|
||||
cdef cvSmoothPtr c_cvSmooth
|
||||
c_cvSmooth = (<cvSmoothPtr*><size_t>ctypes.addressof(cv.cvSmooth))[0]
|
||||
|
||||
#######################################################################
|
||||
# Utility Stuff for the C side. Struct creation, error checking, etc..
|
||||
#######################################################################
|
||||
|
||||
####################################
|
||||
# Function Implementations
|
||||
####################################
|
||||
def cvSobel(np.ndarray src, np.ndarray out=None, int xorder=1, int yorder=0,
|
||||
int aperture_size=3):
|
||||
|
||||
validate_array(src)
|
||||
assert_dtype(src, [UINT8, INT8, FLOAT32])
|
||||
assert_nchannels(src, [1])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
if out is not None:
|
||||
validate_array(out)
|
||||
assert_not_sharing_data(src, out)
|
||||
assert_same_shape(src, out)
|
||||
assert_nchannels(out, [1])
|
||||
if src.dtype == UINT8 or src.dtype == INT8:
|
||||
assert_dtype(out, [INT16])
|
||||
else:
|
||||
assert_dtype(out, [FLOAT32])
|
||||
else:
|
||||
if src.dtype == UINT8 or src.dtype == INT8:
|
||||
out = new_array_like_diff_dtype(src, INT16)
|
||||
else:
|
||||
out = new_array_like(src)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvSobel(&srcimg, &outimg, xorder, yorder, aperture_size)
|
||||
|
||||
return out
|
||||
|
||||
def cvLaplace(np.ndarray src, np.ndarray out=None, int aperture_size=3):
|
||||
validate_array(src)
|
||||
assert_dtype(src, [UINT8, INT8, FLOAT32])
|
||||
assert_nchannels(src, [1])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
|
||||
if out is not None:
|
||||
validate_array(out)
|
||||
assert_not_sharing_data(src, out)
|
||||
assert_same_shape(src, out)
|
||||
assert_nchannels(out, [1])
|
||||
if src.dtype == UINT8 or src.dtype == INT8:
|
||||
assert_dtype(out, [INT16])
|
||||
else:
|
||||
assert_dtype(out, [FLOAT32])
|
||||
else:
|
||||
if src.dtype == UINT8 or src.dtype == INT8:
|
||||
out = new_array_like_diff_dtype(src, INT16)
|
||||
else:
|
||||
out = new_array_like(src)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvLaplace(&srcimg, &outimg, aperture_size)
|
||||
|
||||
return out
|
||||
|
||||
def cvCanny(np.ndarray src, np.ndarray out=None, double threshold1=10,
|
||||
double threshold2=50, int aperture_size=3):
|
||||
validate_array(src)
|
||||
assert_nchannels(src, [1])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
|
||||
if out is not None:
|
||||
validate_array(out)
|
||||
assert_nchannels(out, [1])
|
||||
assert_same_shape(src, out)
|
||||
assert_not_sharing_data(src, out)
|
||||
else:
|
||||
out = new_array_like(src)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvCanny(&srcimg, &outimg, threshold1, threshold2, aperture_size)
|
||||
|
||||
return out
|
||||
|
||||
def cvPreCornerDetect(np.ndarray src, np.ndarray out=None, int aperture_size=3):
|
||||
validate_array(src)
|
||||
assert_dtype(src, [UINT8, FLOAT32])
|
||||
assert_nchannels(src, [1])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
if out is not None:
|
||||
validate_array(out)
|
||||
assert_same_shape(src, out)
|
||||
assert_dtype(out, [FLOAT32])
|
||||
assert_not_sharing_data(src, out)
|
||||
else:
|
||||
out = new_array_like_diff_dtype(src, FLOAT32)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvPreCornerDetect(&srcimg, &outimg, aperture_size)
|
||||
|
||||
return out
|
||||
|
||||
def cvCornerEigenValsAndVecs(np.ndarray src, int block_size=3,
|
||||
int aperture_size=3):
|
||||
|
||||
# no option for the out argument on this one. Its easier just
|
||||
# to make it for them as there is only 1 valid out array for any
|
||||
# given source array
|
||||
|
||||
validate_array(src)
|
||||
assert_nchannels(src, [1])
|
||||
assert_dtype(src, [UINT8, FLOAT32])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
cdef np.npy_intp outshape[2]
|
||||
outshape[0] = src.shape[0]
|
||||
outshape[1] = src.shape[1] * <np.npy_intp>6
|
||||
|
||||
out = new_array(2, outshape, FLOAT32)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvCornerEigenValsAndVecs(&srcimg, &outimg, block_size, aperture_size)
|
||||
|
||||
return out.reshape(out.shape[0], -1, 6)
|
||||
|
||||
def cvCornerMinEigenVal(np.ndarray src, int block_size=3,
|
||||
int aperture_size=3):
|
||||
|
||||
# no option for the out argument on this one. Its easier just
|
||||
# to make it for them as there is only 1 valid out array for any
|
||||
# given source array
|
||||
|
||||
validate_array(src)
|
||||
assert_nchannels(src, [1])
|
||||
assert_dtype(src, [UINT8, FLOAT32])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
out = new_array_like_diff_dtype(src, FLOAT32)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvCornerMinEigenVal(&srcimg, &outimg, block_size, aperture_size)
|
||||
|
||||
return out
|
||||
|
||||
def cvCornerHarris(np.ndarray src, int block_size=3, int aperture_size=3,
|
||||
double k=0.04):
|
||||
|
||||
# no option for the out argument on this one. Its easier just
|
||||
# to make it for them as there is only 1 valid out array for any
|
||||
# given source array
|
||||
|
||||
validate_array(src)
|
||||
assert_nchannels(src, [1])
|
||||
assert_dtype(src, [UINT8, FLOAT32])
|
||||
|
||||
if (aperture_size != 3 and aperture_size != 5 and aperture_size != 7):
|
||||
raise ValueError('aperture_size must be 3, 5, or 7')
|
||||
|
||||
out = new_array_like_diff_dtype(src, FLOAT32)
|
||||
|
||||
cdef IplImage srcimg
|
||||
cdef IplImage outimg
|
||||
populate_iplimage(src, &srcimg)
|
||||
populate_iplimage(out, &outimg)
|
||||
|
||||
c_cvCornerHarris(&srcimg, &outimg, block_size, aperture_size, k)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def cvSmooth(np.ndarray src, np.ndarray out=None, int smoothtype=CV_GAUSSIAN, int param1=3,
|
||||
int param2=0, double param3=0, double param4=0, bool in_place=False):
|
||||
|
||||
|
||||
@@ -33,4 +33,10 @@ cdef struct _IplImage:
|
||||
|
||||
ctypedef _IplImage IplImage
|
||||
|
||||
|
||||
ctypedef struct CvPoint2D32F:
|
||||
float x
|
||||
float y
|
||||
|
||||
ctypedef struct CvSize:
|
||||
int width
|
||||
int height
|
||||
|
||||
Reference in New Issue
Block a user