# Fractals/Iterations in the complex plane/btm

How to identify outer boundaries in a 2D grid of points?
names
* boundary delineation
* edge detection
* contour tracing
Types
* one component at a time ( boundary tracing)
* all components at a time ( edge detection)

## BTM

Boundary trace method ( BTM)
Boundary tracing of a binary digital region can be thought of as a segmentation technique that identifies the boundary pixels of the digital region. Boundary tracing is an important first step in the analysis of that region.

### definition

Boundary is a topological notion. However, a digital image is no topological space. Therefore, it is impossible to define the notion of a boundary in a digital image mathematically exactly. Most publications about tracing the boundary of a subset S of a digital image I describe algorithms which find a set of pixels belonging to S and having in their direct neighborhood pixels belonging both to S and to its complement I - S. According to this definition the boundary of a subset S is different from the boundary of the complement I – S which is a topological paradox.
To define the boundary correctly it is necessary to introduce a topological space corresponding to the given digital image. Such space can be a two-dimensional abstract cell complex. It contains cells of three dimensions: the two-dimensional cells corresponding to pixels of the digital image, the one-dimensional cells or “cracks” representing short lines lying between two adjacent pixels, and the zero-dimensional cells or “points” corresponding to the corners of pixels. The boundary of a subset S is then a sequence of cracks and points while the neighborhoods of these cracks and points intersect both the subset S and its complement I – S. The boundary defined in this way corresponds exactly to the topological definition and corresponds also to our intuitive imagination of a boundary because the boundary of S should contain neither elements of S nor those of its complement. It should contain only elements lying between S and the complement. This are exactly the cracks and points of the complex.
This method of tracing boundaries is described in the book of Vladimir A. Kovalevsky and in the web site.

### Algorithms

Algorithms used for boundary tracing:
* Square tracing algorithm
* Moore-neighbor tracing algorithm
* Radial sweep
* Theo Pavlidis’ algorithm
* A generic approach using vector algebra for tracing of a boundary can be found at.
* An extension of boundary tracing for segmentation of traced boundary into open and closed sub-section is described at.

### Square tracing algorithm

The square tracing algorithm is simple, yet effective. Its behavior is completely based on whether one is on a black, or a white cell (assuming white cells are part of the shape). First, scan from the upper left to right and row by row. Upon entering your first white cell, the core of the algorithm starts. It consists mainly of two rules:
* If you are in a white cell, go left.
* If you are in a black cell, go right.
Keep in mind that it matters how you entered the current cell, so that left and right can be defined.

### Moore-neighbor tracing algorithm

The idea behind the formulation of Moore neighborhood is to find the contour of a given graph. This idea was a great challenge for most analysts of the 18th century, and as a result an algorithm was derived from the Moore graph which was later called the Moore Neighborhood algorithm.
Algorithm:
* Traverse 2D matrix in row wise
* Set the first nonzero pixel as S(Starting of the boundary)
* Set the current pixel as p ; Add this non zero pixel into a boundary pixel list
* Set the previous pixel from where p is entered as b (Backtracked pixel )
* Take a 3 * 3 neighborhood of p and search for the next clockwise nonzero pixel from b in clockwise direction
* Repeat the steps 3 to 5 until p is same as S
The pseudocode for the Moore-Neighbor tracing algorithm is

#### Termination condition

The original termination condition was to stop after visiting the start pixel for the second time. This limits the set of contours the algorithm will walk completely. An improved stopping condition proposed by Jacob Eliosoff is to stop after entering the start pixel for the second time in the same direction you originally entered it.

## BSM/J

BSM = Boundary Scanning Method
This algorithm is used when dynamical plane consist of two of more basins of attraction. For example for c=0.
It is not appropiate when interior of filled Julia set is empty, for example for c=i.
Description of algorithm :
* for every pixel of dynamical plane $z$ do :
** compute 4 corners ( vertices) of pixel $z_{lt},z_{rt},z_{rb},z_{lb}$ ( where lt denotes left top, rb denotes right bottom, ... )
** check to which basin corner belongs ( standard escape time and bailout test )
** if corners do not belong to the same basin mark it as Julia set
Examples of code
* program in Pascal
* via convolution with a kernel

## Dictionary

* image
** 2D
** “segmented” image (an image with foreground pixels labeled 1 and background pixels labeled zero) = binary image
* connectedness and neighberhood
** 4
** 8
* boundary = boundary contour = contour
** inner boundary (outermost pixels of foreground)
** outer boundary (innermost pixels of background):
* trace ( tracing)
** Contour Tracing Algorithms by Abeer George Ghuneim

## papers

* Boundary tracing in binary images
* Wilhelm Burger · Mark J. Burge: Digital Image Processing An algorithmic introduction using Java

## Video

* Mandelbrot Animation (Boundary Tracing / Recursion) by Gnarly Charley

## Code

* fractint
* Java code ( from the video) by Gnarly Charley ( charlesk26 )
* Tracing Boundary in 2D Image Using Moore Neighborhood Approach in C++ by Udaya K Unnikrishnan
* Moore Neighbor Contour Tracing Algorithm in C++ BY ERIK SMISTAD
* Potrace(TM) is a tool for tracing a bitmap by Peter Selinger
* Traces the boundary of a set of points ( python)
* Source code for 'Modern Algorithms for Image Processing' by Vladimir Kovalevsky

## See also

* Pathfinding
* Curve sketching
* Chain code
* Pixel connectivity
* Optimization problem
* Hole Detection
* boundary cleaning: the jagged boundaries are cleaned (smoothed) in order to obtain a pleasant shape

# References

* ↑ wikipedia : boundary tracing
* ↑ Image Processing, Analysis, and Machine Vision Milan Sonka, Vaclav Hlavac, and Roger Boyle
* ↑ Kovalevsky, V., Image Processing with Cellular Topology, Springer 2021, ISBN 978-981-16-5771-9
* ↑ http://www.kovalevsky.de, Lecture "Tracing Boundaries in 2D Images"
* ↑ Contour Tracing Algorithms
* ↑ Abeer George Ghuneim: square tracing algorithm
* ↑ Abeer George Ghuneim: The Radial Sweep algorithm
* ↑ Abeer George Ghuneim: Theo Pavlidis' Algorithm
* ↑ Vector Algebra Based Tracing of External and Internal Boundary of an Object in Binary Images, Journal of Advances in Engineering Science Volume 3 Issue 1, January–June 2010, PP 57–70
* ↑ Graph theory based segmentation of traced boundary into open and closed sub-sections, Computer Vision and Image Understanding, Volume 115, Issue 11, November 2011, pages 1552–1558
* ↑ codeproject article: tracing-boundary-in-d-image-using-moore-neighborho by Udaya K Unnikrishnan
* ↑ Pascal program fo BSM/J by Morris W. Firebaugh
* ↑ Boundary scanning and complex dynamics by Mark McClure