Creates a circular binary mask/brush for morphological operations.
Parameters: |
-
diameter
(float )
–
Diameter of the circle in grid units.
-
size
(int | None , default:
None
)
–
Optional size of the output array. If None, uses ceil(diameter) rounded
up to next odd number.
|
Returns: |
-
Array
–
jax.Array: Binary array containing a circular mask where True indicates points
-
Array
–
within the circle diameter.
|
Source code in src/fdtdx/objects/device/parameters/discretization.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290 | def circular_brush(
diameter: float,
size: int | None = None,
) -> jax.Array:
"""Creates a circular binary mask/brush for morphological operations.
Args:
diameter (float): Diameter of the circle in grid units.
size (int | None, optional): Optional size of the output array. If None, uses ceil(diameter) rounded
up to next odd number.
Returns:
jax.Array: Binary array containing a circular mask where True indicates points
within the circle diameter.
"""
if size is None:
s = math.ceil(diameter)
if s % 2 == 0:
s += 1
size = s
xy = jnp.stack(jnp.meshgrid(*map(jnp.arange, (size, size)), indexing="xy"), axis=-1) - jnp.asarray((size / 2) - 0.5)
euc_dist = jnp.sqrt((xy**2).sum(axis=-1))
# the less EQUAL here is important, because otherwise design may be infeasible due to discretization errors
mask = euc_dist <= (diameter / 2)
return mask
|