mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
add histogram_increment and decrement to core8
This commit is contained in:
+21
-27
@@ -23,6 +23,14 @@ cdef inline np.uint8_t uint8_min(np.uint8_t a, np.uint8_t b): return a if a <= b
|
||||
# 8 bit core kernel
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
cdef inline void histogram_increment(Py_ssize_t* histo,float *pop,np.uint8_t value):
|
||||
histo[value] += 1
|
||||
pop[0] += 1.
|
||||
|
||||
cdef inline void histogram_decrement(Py_ssize_t* histo,float *pop,np.uint8_t value):
|
||||
histo[value] -= 1
|
||||
pop[0] -= 1.
|
||||
|
||||
cdef inline np.uint8_t is_in_mask(Py_ssize_t rows, Py_ssize_t cols,Py_ssize_t r, Py_ssize_t c,np.uint8_t* mask):
|
||||
""" returns 1 if given(r,c) coordinate are within the image frame ([0-rows],[0-cols]) and
|
||||
inside the given mask
|
||||
@@ -157,9 +165,7 @@ cdef inline _core8(np.uint8_t kernel(Py_ssize_t*, float, np.uint8_t, float, floa
|
||||
cc = c - centre_c
|
||||
if selem[r, c]:
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] += 1
|
||||
pop += 1.
|
||||
histogram_increment(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
r = 0
|
||||
c = 0
|
||||
@@ -176,16 +182,13 @@ cdef inline _core8(np.uint8_t kernel(Py_ssize_t*, float, np.uint8_t, float, floa
|
||||
rr = r + se_e_r[s]
|
||||
cc = c + se_e_c[s]
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] += 1
|
||||
pop += 1.
|
||||
histogram_increment(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
for s in range(num_se_w):
|
||||
rr = r + se_w_r[s]
|
||||
cc = c + se_w_c[s] - 1
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] -= 1
|
||||
pop -= 1.
|
||||
histogram_decrement(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
# kernel --------------------------------------------------------------------
|
||||
out_data[r * cols + c] = kernel(histo,pop,image_data[r * cols + c],p0,p1,s0,s1)
|
||||
@@ -200,16 +203,13 @@ cdef inline _core8(np.uint8_t kernel(Py_ssize_t*, float, np.uint8_t, float, floa
|
||||
rr = r + se_s_r[s]
|
||||
cc = c + se_s_c[s]
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] += 1
|
||||
pop += 1.
|
||||
histogram_increment(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
for s in range(num_se_n):
|
||||
rr = r + se_n_r[s] - 1
|
||||
cc = c + se_n_c[s]
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] -= 1
|
||||
pop -= 1.
|
||||
histogram_decrement(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
# kernel --------------------------------------------------------------------
|
||||
out_data[r * cols + c] = kernel(histo,pop,image_data[r * cols + c],p0,p1,s0,s1)
|
||||
@@ -221,16 +221,13 @@ cdef inline _core8(np.uint8_t kernel(Py_ssize_t*, float, np.uint8_t, float, floa
|
||||
rr = r + se_w_r[s]
|
||||
cc = c + se_w_c[s]
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] += 1
|
||||
pop += 1.
|
||||
histogram_increment(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
for s in range(num_se_e):
|
||||
rr = r + se_e_r[s]
|
||||
cc = c + se_e_c[s] + 1
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] -= 1
|
||||
pop -= 1.
|
||||
histogram_decrement(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
# kernel --------------------------------------------------------------------
|
||||
out_data[r * cols + c] = kernel(histo,pop,image_data[r * cols + c],p0,p1,s0,s1)
|
||||
@@ -245,16 +242,13 @@ cdef inline _core8(np.uint8_t kernel(Py_ssize_t*, float, np.uint8_t, float, floa
|
||||
rr = r + se_s_r[s]
|
||||
cc = c + se_s_c[s]
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] += 1
|
||||
pop += 1.
|
||||
histogram_increment(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
for s in range(num_se_n):
|
||||
rr = r + se_n_r[s] - 1
|
||||
cc = c + se_n_c[s]
|
||||
if is_in_mask(rows,cols,rr,cc,mask_data):
|
||||
value = image_data[rr * cols + cc]
|
||||
histo[value] -= 1
|
||||
pop -= 1.
|
||||
histogram_decrement(histo,&pop,image_data[rr * cols + cc])
|
||||
|
||||
# kernel --------------------------------------------------------------------
|
||||
out_data[r * cols + c] = kernel(histo,pop,image_data[r * cols + c],p0,p1,s0,s1)
|
||||
|
||||
Reference in New Issue
Block a user