Cython generate Mask Boundaries
Mon Feb 13 2023 22:44:08 GMT+0000 (Coordinated Universal Time)
Saved by
@MaVCArt
#python
#cython
# ----------------------------------------------------------------------------------------------------------------------
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
@cython.nonecheck(False)
cpdef object get_boundaries(object data):
"""
For a given field of pixels, this method returns a black and white mask, by using the "get_row_boundaries" method
for each row and column.
This is pretty fast, as it can rely on the power of numpy to do this operation very quickly.
"""
cdef object rows = data.copy().astype(float)
# -- row boundaries
for i in range(len(data)):
rows[i] = get_row_boundaries(data[i])
# -- to get the boundary mask of our columns, transpose the image, shifting columns into rows
cdef object columns = data.copy().T
cdef object column_data = data.T
# -- column boundaries
for i in range(len(column_data)):
columns[i] = get_row_boundaries(column_data[i])
# -- having created our column mask, transpose it back.
columns = columns.T
# -- now combine both maps.
return np.maximum(rows, columns)
content_copyCOPY
Comments