Random walker¶
| Fact | Value |
|---|---|
| Also called | Random walk segmentation, Grady random walker |
| Status | Implemented and tested |
| Family | Segmentation and regions |
| Engine | Science engine |
| Type | Nonlinear, iterative, random walk on a graph |
| Output | Labels |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/interactive.py, random_walker_filter |
| Operator code | engine/src/pixelnexus_engine/filters/interactive.py, random_walker_representation |
| Packages | scikit-image |
Overview¶
The random walker splits the image into object and background from a few seeds, after Grady. Picture a walker at each pixel that steps to a neighbor at random, and rarely across an edge. The pixel joins the seed its walker most likely reaches first. scikit-image finds these chances exactly, by solving one linear system. The object goes to the Features panel and is drawn over the image. Click its row number to make it the selection. The filter runs in the PixelNexus engine, with scikit-image.
How it works¶
- Read the object and background seeds from the selection.
- Weigh each link between neighbors by how alike they are.
- Solve the linear system for the object probability of every unknown pixel.
- Each pixel joins the object where its probability is at least one half.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(w_{ij}\): The weight between neighbors i and j
- \(\beta\): The edge strength
- \(\sigma_Y\): The standard deviation of the luma
- \(L_U\): The Laplacian of the graph on the unknown pixels
- \(x\): The probability of the object
Each pixel is a node joined to its 4 neighbors with the weight w, high between similar pixels. Y is the luma from 0 to 1 and sigma Y its standard deviation over the image. A walker at a pixel steps to a neighbor with a chance in proportion to w. Grady showed that the chance x of reaching an object seed first solves a Dirichlet problem on the graph. The Laplacian L of the graph splits into the unknown pixels U and the seeds M, with the block B between them. The chance x is 1 at object seeds and 0 at background seeds. Solving for the unknown x gives the probability at every pixel. Each pixel takes the label with the higher probability.
Grady noticed that the chance of reaching a seed first is the same as the voltage in an electric circuit. The links are resistors with conductance w. The object seeds are held at 1 volt and the background seeds at 0. The voltage at every other pixel solves a Laplace equation on the graph, which is a sparse linear system. No walker is ever simulated.
The result is a probability as well as a label. Pixels near 0.5 are where the walker is unsure, often far from all seeds or across weak edges.
Kernel or operator¶
There is no kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Object | Object, Boundaries over the image, Object probability | The object as a label map, drawn over the image and listed in the Features panel. Or its boundary in yellow over the image. Or the probability of the object at each pixel, from black for 0 to white for 1. |
Seeds seeds |
Selection and image edge | Selection and image edge, Selection as a map | With the selection and image edge, the selected pixels are object seeds and the unselected pixels on the image edge are background seeds. As a map, pixels selected at 192 or more are object seeds, those at 63 or less are background seeds, and partly selected pixels are unknown. |
Edge strength beta |
130 | 1 to 2000 | The beta in the edge weights. scikit-image divides it by 10 times the standard deviation of the luma. scikit-image uses 130. |
Tolerance tolerance |
0.001 | 1e-05 to 0.1 | When the conjugate gradient solver stops. scikit-image uses 0.001. |
Implementation¶
random_walker_filter in engine/src/pixelnexus_engine/filters/interactive.py passes the luma from 0 to 1 to skimage.segmentation.random_walker, with label 1 for object seeds and 2 for background seeds. It uses the conjugate gradient solver with a Jacobi preconditioner (mode cg_j), and asks for the probability of each label. The object is where the object probability is at least one half, so the object wins a tie, as in scikit-image. The seeds come from the selection, as the Seeds parameter says.
The selection is only an input here. Its catalog entry sets selectionRole: markers, so the studio runs the filter on the whole image. The object is a label map with one label.
Worked example¶
| Edge strength beta | Seeds | Area (px) | Overlap | Share of the square |
|---|---|---|---|---|
| 30 | Spot | 1201 | 0.490 | 0.00 |
| 30 | Map | 1124 | 0.458 | 0.00 |
| 130 | Spot | 1396 | 0.569 | 0.00 |
| 130 | Map | 1311 | 0.534 | 0.00 |
| 500 | Spot | 2362 | 0.952 | 0.00 |
| 500 | Map | 2358 | 0.951 | 0.00 |
The image of the figure. Spot is the small square selected inside the disk, with the image edge as background. Map also marks a small square inside the square as background. The disk has 2453 pixels. The overlap is the area of the object and the disk together divided by the area of either. The share of the square is the part of the square inside the object.
At scikit-image's beta of 130, the object covers only about half of the disk. The disk edge is blurred, so the brightness rises over a few pixels, and each step across it is small. So the edge is a weak barrier, and the many background seeds on the image edge win the outer part of the disk. A tighter solver tolerance gave the same result, so it is not a matter of the solver. At a beta of 500, the edge holds and the overlap is 0.952.
The square never joins the object, with or without a seed in it. It lies closer to the many seeds on the image edge than to the small seed in the disk.
Complexity¶
- Time: \(O(N k)\)
- Memory: \(O(N)\)
N is the number of pixels and k the number of conjugate gradient steps.
Artifacts and limitations¶
Limitations
- Only brightness, not color.
- A region with no seed goes to the side it is best linked to, which may be the wrong one.
Artifacts
- Boundaries that cut straight across an area far from all seeds.
Tests¶
The probability must be scikit-image's on the luma. From a spot in a noisy disk with sharp edges, the object must overlap the disk by more than 0.95. The probability output must be white at the seed and black at the image edge. The representation must have its four stages.
References¶
- Grady, L. Random walks for image segmentation. IEEE Transactions on Pattern Analysis and Machine Intelligence 28(11), 1768 to 1783, 2006. DOI 10.1109/TPAMI.2006.233.
- scikit-image documentation, skimage.segmentation.random_walker.