Alternating sequential filter¶
| Fact | Value |
|---|---|
| Also called | ASF |
| Status | Implemented and tested |
| Family | Morphological filters |
| Engine | Browser |
| Type | Nonlinear, spatial, openings and closings of growing size |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | 2 size (size + 1) |
| Code | web/src/core/filters/morphology/reconstruction.ts, asfFilter |
| Operator code | web/src/core/filters/morphology/reconstruction.ts, morphology |
| Channels | RGB, Brightness only |
Overview¶
An alternating sequential filter opens and closes the image with an element of size 1, then size 2, and so on up to a chosen size. It removes bright and dark details of growing size step by step, which disturbs large structures less than one large opening and closing.
How it works¶
- Open and close with the element of size 1.
- Open and close with the element of size 2.
- Continue up to the largest size.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(B_i\): The element of size i
- \(n\): The largest size
f_0 is the image and B_i the element of size i. Each size opens and then closes, or closes and then opens. Growing the size step by step removes small details first, so large structures are disturbed less than with one large opening and closing.
An opening alone removes bright noise and a closing alone dark noise, and a large element in one step also damages large structures. Serra proposed alternating openings and closings with growing elements. Each stage removes the details of its size, so the later, larger stages see an image that is already simpler.
Kernel or operator¶
There is no single kernel. The Inspector lists the stages, one per size, with their elements.
Algorithm¶
- Extend the image by the full reach of all steps with the border mode.
- For each size from 1 to n, open and close with the element of that size, in the chosen order.
- Cut the extension off.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Element shape shape |
Disk | Disk, Square, Diamond | The shape of the elements. Size i uses disk i, the square of side 2 i + 1, or diamond i. |
Largest size size |
3 | 1 to 6 | The number of sizes. Each size adds an opening and a closing. |
Order order |
Opening first | Opening first, Closing first | Whether each size opens before it closes, or closes before it opens. |
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 |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
asfFilter in web/src/core/filters/morphology/reconstruction.ts extends the image once by the reach of all stages with the border mode, runs the openings and closings from web/src/core/filters/morphology/gray.ts, and cuts the extension off. The filter runs in the browser engine through the shared filter framework in web/src/core/filters/run.ts, which handles the channel scope and alpha.
Worked example¶
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| Input | 10 | 10 | 40 | 10 | 10 | 90 | 120 | 90 | 10 | 10 |
| ASF, size 1 | 10 | 10 | 10 | 10 | 10 | 90 | 90 | 90 | 10 | 10 |
Size 1 opens and then closes with the 3 x 3 square. The opening removes the narrow peak at x = 2 and cuts the top of the wide peak, one pixel wide, to 90. The closing then has nothing to fill.
Complexity¶
- Time: \(O(N n^3)\)
- Memory: \(O(N)\)
N is the number of pixels per channel and n the largest size. Element i holds about i^2 pixels.
Artifacts and limitations¶
Limitations
- Slow for large sizes.
- The order of opening and closing changes the result a little.
Artifacts
- Shapes take on the outline of the element.
Tests¶
The reference runs scipy.ndimage.grey_erosion and grey_dilation with the same elements on the extended plane. The cases cover two shapes, two sizes, both orders and all five border modes.
References¶
- Vincent, L. Morphological grayscale reconstruction in image analysis, applications and efficient algorithms. IEEE Transactions on Image Processing 2(2), 176 to 201, 1993. DOI 10.1109/83.217222.
- Serra, J. Image Analysis and Mathematical Morphology, Volume 2. Academic Press, 1988.
- Soille, P. Morphological Image Analysis, 2nd edition. Springer, 2004. DOI 10.1007/978-3-662-05088-0.