55
66
77def rolling_ball (image , * , radius = 100 , kernel = None , nansafe = False , num_threads = None ):
8- """Estimate background intensity by rolling/ translating a kernel.
8+ """Estimate background intensity by translating a kernel over an image .
99
10- This rolling ball algorithm estimates background intensity for a
11- ndimage in case of uneven exposure. It is a generalization of the
12- frequently used rolling ball algorithm [1]_.
10+ This function estimates the background intensity of an n-dimensional
11+ image. Typically, it is useful for background subtraction in case of
12+ uneven exposure. It is a generalization of the well-known rolling-ball
13+ algorithm [1]_.
1314
1415 Parameters
1516 ----------
1617 image : ndarray
1718 The image to be filtered.
1819 radius : int, optional
19- Radius of a ball-shaped kernel to be rolled/ translated in the image.
20- Used if `` kernel = None``.
20+ Radius of the ball-shaped kernel to be translated over the
21+ image. Used only if `kernel` is `` None``.
2122 kernel : ndarray, optional
22- The kernel to be rolled/translated in the image. It must have the
23- same number of dimensions as ``image``. Kernel is filled with the
24- intensity of the kernel at that position.
23+ The kernel to be translated over the image. It must have the
24+ same number of axes as `image`.
2525 nansafe: bool, optional
26- If ``False`` (default) assumes that none of the values in ``image``
27- are ``np.nan``, and uses a faster implementation.
26+ If ``False`` (default), the function assumes that none of the values
27+ in `image` are ``np.nan``, and uses a faster implementation.
2828 num_threads: int, optional
29- The maximum number of threads to use. If ``None`` use the OpenMP
30- default value; typically equal to the maximum number of virtual cores.
29+ The maximum number of threads to use. If ``None``, the function uses
30+ the OpenMP default value; typically, it is equal to the maximum number
31+ of virtual cores.
3132 Note: This is an upper limit to the number of threads. The exact number
3233 is determined by the system's OpenMP library.
3334
@@ -38,20 +39,23 @@ def rolling_ball(image, *, radius=100, kernel=None, nansafe=False, num_threads=N
3839
3940 Notes
4041 -----
41- For the pixel that has its background intensity estimated (without loss
42- of generality at ``center``) the rolling ball method centers ``kernel``
43- under it and raises the kernel until the surface touches the image umbra
44- at some ``pos=(y,x)``. The background intensity is then estimated
45- using the image intensity at that position (``image[pos]``) plus the
46- difference of ``kernel[center] - kernel[pos]``.
42+ The algorithm is easy to grasp in 2D: Consider that each pixel value
43+ defines a height, forming a 2D surface in 3D space. Then, a (3D) ball of
44+ given radius (or a kernel, in the general case) is placed under this
45+ surface and raised until it touches it. The background intensity is
46+ estimated by the hull of the volume reachable by the ball.
4747
48- This algorithm assumes that dark pixels correspond to the background. If
49- you have a bright background, invert the image before passing it to the
50- function, e.g., using `utils.invert`. See the gallery example for details.
48+ Clearly, for this method to give meaningful results, the radius of the
49+ ball (or typical size of the kernel, in the general case) should be (much)
50+ larger than the typical size of the image features of interest.
51+
52+ This implementation assumes that dark pixels correspond to the background. If
53+ you have a bright background, invert the image before passing it to this
54+ function, e.g., using :func:`skimage.util.invert`. See the gallery example for details.
5155
5256 This algorithm is sensitive to noise (in particular salt-and-pepper
5357 noise). If this is a problem in your image, you can apply mild
54- gaussian smoothing before passing the image to this function.
58+ Gaussian smoothing before passing the image to this function.
5559
5660 This algorithm's complexity is polynomial in the radius, with degree equal
5761 to the image dimensionality (a 2D image is N^2, a 3D image is N^3, etc.),
0 commit comments