mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
Added star structural element
This commit is contained in:
@@ -5,7 +5,7 @@ from .grey import (erosion, dilation, opening, closing, white_tophat,
|
||||
greyscale_open, greyscale_close, greyscale_white_top_hat,
|
||||
greyscale_black_top_hat)
|
||||
from .selem import (square, rectangle, diamond, disk, cube, octahedron, ball,
|
||||
octagon)
|
||||
octagon, star)
|
||||
from .ccomp import label
|
||||
from .watershed import watershed, is_local_maximum
|
||||
from ._skeletonize import skeletonize, medial_axis
|
||||
|
||||
@@ -232,8 +232,9 @@ def octagon(m, n, dtype=np.uint8):
|
||||
Returns
|
||||
-------
|
||||
selem : ndarray
|
||||
The structuring element where elements of the neighborhood
|
||||
are 1 and 0 otherwise.
|
||||
The structuring element where elements of the neighborhood
|
||||
are 1 and 0 otherwise.
|
||||
|
||||
"""
|
||||
from . import convex_hull_image
|
||||
selem = np.zeros((m + 2*n, m + 2*n))
|
||||
@@ -247,3 +248,46 @@ def octagon(m, n, dtype=np.uint8):
|
||||
selem[m + n - 1, -1] = 1
|
||||
selem = convex_hull_image(selem).astype(dtype)
|
||||
return selem
|
||||
|
||||
|
||||
def star(a, dtype=np.uint8):
|
||||
"""
|
||||
Generates a star shaped structuring element that is an overlap of square
|
||||
of size `2*a + 1` with its 45 degree rotated version. The slanted sides
|
||||
are 45 or 135 degrees to the horizontal axis.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
a : int
|
||||
Parameter deciding the size of the star structural element. The side
|
||||
of the square array returned is `2*a + 1 + 2*floor(a / 2)`.
|
||||
|
||||
Other Parameters
|
||||
----------------
|
||||
dtype : data-type
|
||||
The data type of the structuring element.
|
||||
|
||||
Returns
|
||||
-------
|
||||
selem : ndarray
|
||||
The structuring element where elements of the neighborhood
|
||||
are 1 and 0 otherwise.
|
||||
|
||||
"""
|
||||
from . import convex_hull_image
|
||||
if a == 1:
|
||||
bfilter = np.zeros((3, 3))
|
||||
bfilter[:] = 1
|
||||
return bfilter
|
||||
m = 2 * a + 1
|
||||
n = a / 2
|
||||
selem_square = np.zeros((m + 2 * n, m + 2 * n), dtype=np.uint8)
|
||||
selem_square[n: m + n, n: m + n] = 1
|
||||
selem_triangle = np.zeros((m + 2 * n, m + 2 * n), dtype=np.uint8)
|
||||
selem_triangle[(m + 2 * n - 1) / 2, 0] = 1
|
||||
selem_triangle[(m + 1) / 2, n - 1] = 1
|
||||
selem_triangle[(m + 4 * n - 3) / 2, n - 1] = 1
|
||||
selem_triangle = convex_hull_image(selem_triangle).astype(int)
|
||||
selem_triangle += (selem_triangle[:, ::-1] + selem_triangle.T +
|
||||
selem_triangle.T[::-1, :])
|
||||
return selem_square + selem_triangle
|
||||
|
||||
Reference in New Issue
Block a user