Fractals/scanning

Scanning, sampling 

Sampling
 * process of getting a finite number of values from a function, map, image.
 * In statistics, quality assurance, and survey methodology, sampling is the selection of a subset (a statistical sample) of individuals from within a statistical population to estimate characteristics of the whole population. Statisticians attempt to collect samples that are representative of the population in question. Sampling has lower costs and faster data collection than measuring the entire population and can provide insights in cases where it is infeasible to measure an entire population.

Criteria for classifications:
 * number of passes ( single pass, multiple pass)
 * grid ( regular = uniform / irregular or adaptive )
 * random ( stochastic)/ not-random
 * with or without decomposition

Sampling types by range
 * point-sampling = Point-sampling method. A seed is a defined, rationally complex number which represents a pixel = pixel center. Note that one can find infinitely many points inside one pixel, and many of such point can have different color/ behaviour then the pixel center.
 * Spatial sampling ( what happens between samples ? ) : a manually-defined homogeneous grid = uniform sampling
 * 1 pixel approximation = image shows "the set of points in the plane whose distance  to the filled Julia set is at most the diameter of a pixel"
 * supersampling = sub-pixel aproximation ( resolution)

Sampling by adaptation
 * regular, uniform ( non-adaptive) sampling
 * adaptive ( non-uniform)sampling =  Adaptive Mesh Refinement (AMR)
 * Detail Enhancement Based on Local Fractal Analysis of Gradient: The key concept of fractal-based image model is the fractal dimension is capable of representing intrinsic structural information of image robustly.
 * a quadtree decomposition of the complex plane with adaptive refinement gives adaptive approximation
 * Adaptive Subdivision
 * "Mathematica automatically samples more points when needed to create a smooth function visualization"
 * Adaptive Sampling for precise Plotting Math Curve

=Types=
 * standard scanning: rendering the whole image (in full resolution) in one step
 * fractint Drawing_Methods
 * circular rendering on each successive refinement step

Steps:
 * preview
 * final render

Types by transformation or plane type ( parameter or dynamic)
 * scaning the standard c plane
 * scanning the exponential plane

standard
Scan the plane :
 * all pixels ( plane is scanned pixel by pixel ) in one pass
 * the same pixel size ( regular, uniform grid )

It depends also on the plane description

corners
Here in Lisp

and in C

Normal grid-scan plotting by Robert Munafo

radius
another version

quadtree
Quadtree types
 * Region quadtree
 * point quadtree


 * distance_estimation, Koebe 1/4-theorem by Claude Heiland-Allen
 * fast-mandelbrot-set-by-quadtree by Mandrian
 * The Mariani-Silver Algorithm for Drawing the Mandelbrot Set by Rico Mariani
 * Mariani/Silver Algorithm from the Mandelbrot Set Glossary and Encyclopedia, by Robert Munafo, (c) 1987-2022.
 * openprocessing : Quad-tree by Naoki Tsutae

// Quad-tree by Naoki Tsutae in Processing // https://openprocessing.org/sketch/1769288 quadTree = (x, y, size) => { if (size < minRectSize) return; const n = noise((x + posx) * 0.001, (y + posy) * 0.001, variation); if (abs(n - 0.45) > size / maxRectSize) { rect(x, y, size); } else { size /= 2; const d = size / 2; quadTree(x + d, y + d, size); quadTree(x + d, y - d, size); quadTree(x - d, y + d, size); quadTree(x - d, y - d, size); } };

Region quadtree
The region quadtree represents a partition of space in two dimensions by decomposing the region into four equal quadrants, subquadrants, and so on with each leaf node containing data corresponding to a specific subregion. Each node in the tree either has
 * exactly four children
 * or has no children (a leaf node).

The height of quadtrees that follow this decomposition strategy (i.e. subdividing subquadrants as long as there is interesting data in the subquadrant for which more refinement is desired) is sensitive to and dependent on the spatial distribution of interesting areas in the space being decomposed. The region quadtree is a type of trie.

A region quadtree with a depth of n may be used to represent an image consisting of 2n × 2n pixels, where each pixel value is 0 or 1. The root node represents the entire image region. If the pixels in any region are not entirely 0s or 1s, it is subdivided. In this application, each leaf node represents a block of pixels that are all 0s or all 1s. Note the potential savings in terms of space when these trees are used for storing images; images often have many regions of considerable size that have the same colour value throughout. Rather than store a big 2-D array of every pixel in the image, a quadtree can capture the same information potentially many divisive levels higher than the pixel-resolution sized cells that we would otherwise require. The tree resolution and overall size is bounded by the pixel and image sizes.

A region quadtree may also be used as a variable resolution representation of a data field. For example, the temperatures in an area may be stored as a quadtree, with each leaf node storing the average temperature over the subregion it represents.

Koebe quarter theorem:

Once b [the exterior distance estimate for c] is found, by the Koebe 1/4-theorem, we know there's no point of the Mandelbrot set with distance from c smaller than b/4.

Antialiasing and supersampling


Supersampling or supersampling anti-aliasing (SSAA) is a spatial anti-aliasing method, i.e. a method used to remove aliasing (jagged and pixelated edges, colloquially known as "jaggies") from images rendered in computer games or other computer programs that generate imagery. Aliasing occurs because unlike real-world objects, which have continuous smooth curves and lines, a computer screen shows the viewer a large number of small squares. These pixels all have the same size, and each one has a single color. A line can only be shown as a collection of pixels, and therefore appears jagged unless it is perfectly horizontal or vertical. The aim of supersampling is to reduce this effect. Color samples are taken at several instances inside the pixel (not just at the center as normal), and an average color value is calculated. This is achieved by rendering the image at a much higher resolution than the one being displayed, then shrinking it to the desired size, using the extra pixels for calculation. The result is a downsampled image with smoother transitions from one line of pixels to another along the edges of objects.

The number of samples determines the quality of the output.


 * TechInfo -AntiAliasing by Michael Condron
 * Fract (Lisp code) by Yannick Gingras
 * Spatial anti aliasing at wikipedia
 * fractalforums discussion: Antialiasing fractals - how best to do it?

Supersampling, other names:
 * antigrain geometry
 * Supersampling (downsampling)
 * downsizing
 * downscaling
 * subpixel accuracy

Computational cost and adaptive supersampling
Supersampling is computationally expensive because it requires much greater video card memory and memory bandwidth, since the amount of buffer used is several times larger. A way around this problem is to use a technique known as adaptive supersampling, where only pixels at the edges of objects are supersampled.

Initially only a few samples are taken within each pixel. If these values are very similar, only these samples are used to determine the color. If not, more are used. The result of this method is that a higher number of samples are calculated only where necessary, thus improving performance.

Types
When taking samples within a pixel, the sample positions have to be determined in some way. Although the number of ways in which this can be done is infinite, there are a few ways which are commonly used.

Grid
The simplest algorithm. The pixel is split into several sub-pixels, and a sample is taken from the center of each. It is fast and easy to implement. Although, due to the regular nature of sampling, aliasing can still occur if a low number of sub-pixels is used.

Random
Also known as stochastic sampling, it avoids the regularity of grid supersampling. However, due to the irregularity of the pattern, samples end up being unnecessary in some areas of the pixel and lacking in others.

Poisson disk
The poisson disk sampling algorithm places the samples randomly, but then checks that any two are not too close. The end result is an even but random distribution of samples. However, the computational time required for this algorithm is too great to justify its use in real-time rendering, unless the sampling itself is computationally expensive compared to the positioning of the sample points or the sample points are not repositioned for every single pixel.

Poisson-disk sampling (blue noise) is the best sampling pattern. It maximizes the uniformity of the samples in addition to the randomness of their placement, which gets you the most bang for your buck with respect to the contribution of each sample. quaz0r on FF

Links
 * poisson-disc-sampling-in-python by christian on 22 Apr 2017

Jittered
A modification of the grid algorithm to approximate the Poisson disk. A pixel is split into several sub-pixels, but a sample is not taken from the center of each, but from a random point within the sub-pixel. Congregation can still occur, but to a lesser degree. Jitter is also recommended to avoid Moiré artifacts.

Rotated grid
A 2×2 grid layout is used but the sample pattern is rotated to avoid samples aligning on the horizontal or vertical axis, greatly improving antialiasing quality for the most commonly encountered cases. For an optimal pattern, the rotation angle is $arctan (1⁄2)$ (about 26.6°) and the square is stretched by a factor of $$\frac{\sqrt{5}}{2}$$

An example of an image with extreme pseudo-random aliasing
Because fractals have unlimited detail and no noise other than arithmetic round-off error, they illustrate aliasing more clearly than do photographs or other measured data. The escape times, which are converted to colours at the exact centres of the pixels, go to infinity at the border of the set, so colours from centres near borders are unpredictable, due to aliasing. This example has edges in about half of its pixels, so it shows much aliasing. The first image is uploaded at its original sampling rate. (Since most modern software anti-aliases, one may have to download the full-size version to see all of the aliasing.) The second image is calculated at five times the sampling rate and down-sampled with anti-aliasing. Assuming that one would really like something like the average colour over each pixel, this one is getting closer. It is clearly more orderly than the first.

In order to properly compare these images, viewing them at full-scale is necessary.

code

 * Cpp code by User Geek3
 * command line version of Aptus (python and c code) by Ned Batchelder  (see aptuscmd.py) is using  a high-quality downsampling filter thru PIL function resize
 * Java code by Josef Jelinek: supersampling with grid algorithm, computes 4 new points (corners), resulting color is an average of each color component:


 * one can make big image (like 10 000 x 10 000) and convert/resize it (downsize). For example using ImageMagick:

downsampling and interpolating is essentially compression, low frequency components, ie:
 * slow changing colours that change slower than half sampling freq, will get preserved
 * the high frequency detail will be lost

Interval arithmetic

 * adaptive algorithms for generating guaranted images of Julia sets
 * True Shape Algorithm ( TSA)

= How do I optimize searching for the nearest point ?=
 * gamedev.stackexchange question: how-do-i-optimize-searching-for-the-nearest-point ?

=See also=
 * Tessellation is the process of partitioning space into a set of smaller polygons
 * 2D grid types
 * commons:Category:Mesh in computer graphics
 * sampling and the image noise - dither to more accurately display graphics containing a greater range of colors than the display hardware is capable of showing
 * Fractint Drawing Methods
 * Fratal Witchcraft drawing methods by Steven Stoft
 * AlmondBread algorithms
 * rugh set method
 * cell mapping based on interval arithmetic with label propagation in graphs to avoid function iteration and rounding errors
 * "We combine cell mapping based on interval arithmetic with label propagation in graphs to avoid function iteration and rounding errors." - Luiz Henrique de Figueiredo et al.
 * using exterior distance estimates and Koebe quarter theorem
 * usung symmetry

=References=
 * Serious Statistics: The Aliasing Adventure By Guest_Jim March 17, 2019