= 3d Brain Atlas Reconstructor standalone = === Detailed description of gap-filling algorithm === The most common defect encountered in digital (e.g. PDF) versions of published atlases are gaps in structures' outlines. It commonly happens when two contour lines which should touch are drawn so that they leave a little space in between. Such an arrangement may not be visible in a printed atlas but it greatly disturbs tracing process where every pixel may influence the results. In this case the structure being traced overtakes the space of its neighbour through the broken contour which we call leaking of the structure (see figure below). [[Image(debug_476_576_AOM_step_0.png)]] Fragment of rasterized contour slide based on Paxinos and Franklin ''The Mouse Brain In Stereotaxic Coordinates, third edition''. Leaking structures are handled in 3dBAR by gap filling algorithm, an extension of the basic tracing procedure. The algorithm requires single input parameter – `MaxGrowLevel` describing maximal size of the gaps that will be closed during tracing of a particular area. The algorithm creates multiple (`n=MaxGrowLevel`) copies of initial input bitmap, each with the contours expanded using the [http://en.wikipedia.org/wiki/Dilation_%28morphology%29 dilation filter] approximately by one pixel. `Figure - consecutive application of dilation filter` Sizes of consecutive flood-filled areas are compared. If the number of flooded pixels lowers proportionally to boundary length across different levels of gap filling it means that most probably the boundaries of the structure in question do not have any gaps. `Figure - structure without any gaps + consecutive areas` If the reduction of flooded area is grated then expected at certain stage of filter application, it means that boundary gap must have been closed. After finding the optimal number of border expansions (denoted by `GrowLevel`), the resulting region is dilated the same number of times as the boundaries were grown to make the area of the resulting path unbiased and the resulting corrected bitmap is passed to [http://potrace.sourceforge.net/ PoTrace]. The gap filling algorithm is applied individually for each seed label thus different regions may be processed with different value of `GrowLevel`. Information about which `GrowLevel` was used to trace a particular path is stored in its attributes. `Przykład kodu labelki z użytym gap fillem` ==== Preconfiguration ==== The gap filling algorithm may also be preconfigured during the preparation of a contour slide. Preconfiguration is carried out by assigning `bar:growlevel` attribute to the label used as the seed for tracing. The value of this attribute should be an integer between -1 and `MaxGrowLevel`. Assigning `-1` means that `GrowLevel` is undefined and has to be selected automatically, `0` means that gap filling should not be used for this particular label. Other values denote the number of dilation filter applications. ==== Algorithm performance ==== The performance of the algorithm depends on the initial size of the structure and on the resolution of input data but in practice, already for structures on the order of diameter around 10 pixels, gap detection works well. Intensive use of this algorithm may distort or even erase the some (particularly narrow) structures. There is no specific mechanism implemented against such behaviour but in practice we have not encountered problems of this type. If a very accurate reconstruction is required, the best policy is to prepare a precise contour slide so there is no need to apply gap filling.