Matched vessel filter¶
| Fact | Value |
|---|---|
| Also called | Chaudhuri matched filter, Matched filter for blood vessels |
| Status | Implemented and tested |
| Family | Texture, corners, blobs and features |
| Engine | Browser |
| Type | Nonlinear, spatial, oriented matched filters and maximum |
| Output | Image |
| Operator shown as | dynamic-kernel (exact) |
| Support radius | ceil(sqrt((3 sigma)^2 + (length / 2)^2)) |
| Code | web/src/core/filters/features/matched-vessel.ts, matchedVesselFilter |
| Operator code | web/src/core/filters/features/matched-vessel.ts, vesselKernel |
| Channels | Brightness only, RGB |
Overview¶
The matched vessel filter finds thin lines whose brightness across them follows a Gaussian curve, such as blood vessels in retinal photos. It slides a small model of a straight vessel piece over the image in many directions and keeps the best match at each pixel. The result is a map of vessel strength, ready for a threshold, or the direction of the best match.
How it works¶
- Build a kernel that looks like a short dark line with a Gaussian profile, and subtract its mean.
- Turn it to each direction and correlate the image with it.
- Keep the largest response at each pixel, or the direction where it is reached.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(\phi\): The vessel direction
- \(u, v\): Offsets across and along the vessel
- \(L\): The length
- \(m_{\phi}\): The mean of the Gaussian part inside the window
For the vessel direction phi, u = x sin phi + y cos phi is the offset across the vessel and v = x cos phi - y sin phi the offset along it. The y axis points down, so phi turns counterclockwise on screen. The term m_phi is the mean of the Gaussian part over the offsets inside the window, so each kernel adds up to 0 and flat areas give 0. Offsets outside the window have weight 0. Bright vessels use the kernel with the opposite sign. The angle output is the direction of the largest response. When several are within 1e-9 times max(1, |R|) of it, the first wins. The choice of grid offsets inside the window is this filter's own discrete rule.
A matched filter correlates the image with a model of the pattern it looks for. Chaudhuri and colleagues modeled the cross section of a retinal vessel as a Gaussian dip and noted that short pieces of a vessel are nearly straight. Their kernel follows the dip across the vessel and stays constant along it for a short length. Subtracting the mean makes each kernel add up to 0, so slow changes in background brightness give no response. Since a vessel can run in any direction, the kernel is turned to many directions, and the best match wins.
Kernel or operator¶
The Inspector shows the kernel for a horizontal vessel with the current settings. The filter turns it to every direction in the same way.
Algorithm¶
- For each direction, build the kernel on the grid offsets inside the window and subtract its mean.
- Correlate the image with every kernel.
- Keep the largest response, or the direction where it is reached.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Sigma sigma |
2 | 0.5 to 8 px | The width of the Gaussian profile across the vessel. The kernel ends at 3 sigma. |
Length length |
9 | 1 to 41 px | How far the kernel reaches along the vessel. |
Directions orientations |
12 | 1 to 24 | How many vessel directions to try, spread evenly over 180 degrees. |
Vessels are polarity |
Darker than the background | Darker than the background, Brighter than the background | Whether the lines to find are dark or bright. |
Output output |
Largest response | Largest response, Direction of the largest response | The strength of the best match, or the vessel direction in degrees. |
Output mapping outputMapping |
Stretch to full range | Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 | How signed results, such as gradients, become 8-bit pixel values. |
Border mode border |
Reflect 101 (default) | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
vesselKernel in web/src/core/filters/features/matched-vessel.ts builds each kernel on the grid offsets whose distance across the vessel is at most 3 sigma and whose distance along it is at most half the length. This choice of offsets is this filter's own discrete rule. The filter correlates the image with every kernel and keeps the largest response. For the direction output, the first direction within 1e-9 times max(1, |R|) of the largest response wins, so ties do not depend on rounding. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the border mode, the channel scope, alpha and the output mapping. By default it works on luma.
Worked example¶
| u | -3 | -2 | -1 | 0 | 1 | 2 | 3 |
|---|---|---|---|---|---|---|---|
| -exp(-u^2 / 2) | -0.0111 | -0.1353 | -0.6065 | -1 | -0.6065 | -0.1353 | -0.0111 |
| Kernel weight | 0.3469 | 0.2227 | -0.2485 | -0.6420 | -0.2485 | 0.2227 | 0.3469 |
The kernel for a horizontal vessel with sigma 1 and length 5. Across the vessel, u runs over the rows from -3 to 3, the window of 3 sigma. Along it, v runs over the columns from -2 to 2, since |v| must stay within 2.5. Every column of the window has the same profile, so the mean of the window is the mean of one column, -0.3580. Each weight is the profile minus this mean. The weights add up to 0, so a flat area gives 0 and a dark line along the middle row gives a large positive response. The square that holds every direction of the kernel is 9 x 9.
Complexity¶
- Time: \(O(D N w^2)\)
- Memory: \(O(D N)\)
D directions, N pixels per channel and a kernel w pixels wide. The kernels are not separable.
Artifacts and limitations¶
Limitations
- Steps and edges also give a response, though weaker than lines.
- One sigma fits one vessel width. Wide and thin vessels need different settings.
- Strongly curved vessels fit the straight kernel poorly.
Artifacts
- Thin false lines next to strong edges, such as the border of the optic disk.
Tests¶
No common library has this filter, so the reference builds the same kernels in Python and runs scipy.ndimage.correlate. Before the cases are written, the script checks that every kernel adds up to 0. It also checks that a dark Gaussian line at 30 degrees gives its largest response on the line, with the direction 30 on the line. The cases cover both polarities, both outputs and two sizes for all five border modes.
References¶
- Chaudhuri, S., Chatterjee, S., Katz, N., Nelson, M. and Goldbaum, M. Detection of blood vessels in retinal images using two-dimensional matched filters. IEEE Transactions on Medical Imaging 8(3), 263 to 269, 1989. DOI 10.1109/42.34715.