# ----------------------------------------------------------------------------------------------------------------------
@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)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter