Skip to content

Commit

Permalink
Worked on Watershed function
Browse files Browse the repository at this point in the history
  • Loading branch information
bewithaman committed Jul 14, 2015
1 parent d358358 commit 684a44d
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions scipy/ndimage/src/_ni_measure.pyx
Expand Up @@ -37,7 +37,6 @@ cdef extern from "numpy/arrayobject.h" nogil:
void *PyDataMem_NEW(size_t)
void PyDataMem_FREE(void *)


######################################################################
# Use of Cython's type templates for type specialization
######################################################################
Expand Down Expand Up @@ -269,12 +268,29 @@ ctypedef np.intp_t (*funcp_windex1)(void *data, np.intp_t v_index, np.intp_t p_i
np.intp_t p_idx, np.intp_t v_idx, np.flatiter _ii, np.intp_t *vval, np.intp_t *pval, np.ndarray input)

ctypedef np.intp_t (*funcp_windex2) (void *data, np.intp_t v_index, np.intp_t p_index, np.intp_t *strides, np.ndarray output, np.ndarray input,
np.intp_t idx, int o_contiguous, int label)
np.intp_t idx, int o_contiguous, int *label)

################################################################################
# Asociate function Declaration
#################################################################################

cdef void get_index(data_output *data, np.intp_t index, np.intp_t *strides, np.ndarray array,
np.intp_t rank, np.intp_t *out, np.intp_t contiguous):
cdef int qq
cdef np.intp_t cc, idx

do:
if contiguous:
out[0] = index * sizeof(data_output)
else:
idx = index
out[0] = 0
for qq in range(rank):
cc = idx / strides[qq]
idx -= cc * strides[qq]
out[0] += array.strides[qq] * cc
while False

cdef np.intp_t get_value(data_watershed *data, np.flatiter _iti, PyArrayObject *iti,
np.ndarray array):
#use byteswapped technique
Expand All @@ -296,9 +312,16 @@ cdef np.intp_t case_windex1(data_output *data, np.intp_t v_index, np.intp_t p_in
pval[0] = (<data_output *>(np.PyArray_ITER_DATA(_ii) + p_idx))[0]

cdef np.intp_t case_windex2(data_output *data, np.intp_t v_index, np.intp_t p_index, np.intp_t *strides, np.ndarray output, np.ndarray input,
np.intp_t idx, int o_contiguous, int label):
np.intp_t idx, int o_contiguous, int *label):
# Another function definations
get_index(data, v_index, strides, output, input.ndim, idx, o_contiguous)
label[0] = (<data_output *> data)[0]
#same function call
get_index(data, p_index, strides, output.strides, out, )
(<data_output *> data)[0] = label[0]

# cdef int del = 0

return 1

#############################################################################
Expand Down Expand Up @@ -514,7 +537,7 @@ cpdef int watershed_ift(np.ndarray input, np.ndarray markers, np.ndarray structu
# adapt the cost and the label of the neighbor:
p.cost = max
case_windex2(np.PyArray_ITER_DATA(_li), v_index, p_index, strides, output, input, idx,
o_contiguous, label)
o_contiguous, &label)

# If the neighbor is in a queue, remove it:
if p.next or p.prev is not NULL:
Expand Down

0 comments on commit 684a44d

Please sign in to comment.