Plasma blends and perturbs an input image based on the DiamondSquare Algorithm producing an effect similar to hovering smoke, fog, thin altostratus cloud formations and other undulating hazes. Also see its cousin, turbulence.
G'MIC's implementation samples, blends, and perturbs either images or constant color fields (including black), in the latter case generating cloudlike patterns. Gray scale plasma patterns are often used as height maps for three dimensional mountainous terrain.
As a sampling and blending algorithm, the command tends to preserve the local average intensity within imagery, but with a randomizing component, also introduces visual roughness. Thus plasma shares attributes with both blurring and noisemaking filters, often to singular effect.
The algorithm proceeds in discrete stages from initially coarse to finescale grids, the number of such being set by the scale parameter. At each stage, the algorithm samples the existing image at the current grid intersection points, blends these data into a set of interpolated points, then randomly perturbs these, the intensity of such controlled by scale, alpha and beta (see 'How the Parameters Interact', below). The new sample points, added to those present at the start of a stage, together compose the finermesh sampling grid of the next stage. When the fineness of the grid reaches pixel dimensions, the algorithm ceases.
The DiamondSquare algorithm draws its name from the formation of its sampling grid, which, at a particular stage, consists of horizontally and vertically aligned cells with sides of length d, (the “squares”) and a slightly finer grid with sides d ⁄ √2 orientated at 45° (the “diamonds”). The two sampling and blending grids operate in concert to minimize the formation of horizontally and vertically aligned artifacts that would be otherwise present with grids of a single orientation. The finer grid, consisting of the side midpoints and center points of the coarser grid, combine together with the square grid to form the d /2 square grid of the next stage, from which the next stage diamond grid is derived.
The format of the command is:
plasma _alpha,_beta,_scale
The DiamondSquare algorithm employs a combination of:
Beginning with a coarsemesh grid, the DiamondSquare algorithm progresses through a series of grids, sampleaveraging and perturbing the results at eversofiner scales, stopping at the 1 pixel scale.
Scale sets the number of grids which the algorithm uses, and from which follows directly the coarseness of the initial grid:
d = 2^{s} for d, length of sides of the initial grid, in pixels, and s, scale, given as a parameter.
For large scale parameters, the mesh of the initial grid is very coarse, sample points are far apart and are averaged over a wide distance. Consequently, the very first samples tend to influence pixels over a very wide area and form the basis for large features. A large scale parameter also means that the algorithm will operate over many stages, each with sample points half the distance apart from each other as the previous grid, so that details arising from random perturbations occur at many scales, giving rise to nuanced effects.
On the other hand, small scale parameters lead to initial grids that are already fine, so the range of influence that grid points have is limited and feature size in the final image is small. The number of grids that the algorithm runs through is also small, so the algorithm stops after only a few iterations, further limiting largescale effects. A scale of one operating over a constant color field is barely distinguishable from random noise.
Scale, alpha and beta together establish the perturbation amount at each stage, i, of the algorithm, an amount that generally gets smaller as the algorithm progresses through ever finer grids, though the amount of decay depends on particular choices of the three parameters. Here are the relationships among them:
As the algorithm progresses through the grids, i, from 1 to s, it computes a perturbation offset, P_{i}, which it adds to each new intermediary grid point. P_{i}, in turn, arises from a scaled decay factor, the product of alpha, the first parameter from the command line, and a griddependent scale factor, d_{i}. To this component, the algorithm adds a scale independent factor, beta, the second parameter from the command line. The griddependent decay factor, d_{i} begins as a relatively large factor, when the initial coarse grids are in play, but it decreases by powers of two as the finer grids come into play.
The size of the image virtually places a cap on the effect of scale. A normal plasma has a nearzero, perhaps slightly positive average. That is, the minimum value of a plasmagenerated image is nearly equal in magnitude to the maximum value, and of opposite sign. But as one increases scale without increasing the size of the image, there comes a point when the features in the image do not grow larger. That is because the coarsest grids are larger than the image size itself – recall that these grow by powers of two.
Instead, excessive scale shows up as an image bias. Both the image minimum and maximum grow in tandem. For really excessive values of scale, both the image minimum and maximum will be on the order of a million or ten million, yet be separated by a difference of only a hundred or so. When experimenting with plasmas, keep track of image minima and maxima: if they are not nearly equal and opposite, chances are that scale is uselessly large.
From time to time, you may need to exactly repeat a particular plasma, which, at first blush, may seem well nigh impossible, given all the randomness of the DiamondSquare algorithm. The randomness, however, is of the pseudo sort, and is, in fact, a wholly deterministic process which spits out number sequences that exhibit statistical properties akin to randomness, but if you can figure out how to dive into a particular spot in the sequence – say, the ith position – you'll notice that i + 1 is always the same. Ditto i + 2, and i + 7,593,452, for that matter.
The G'MIC command that lets you dive into a particular spot in the pseudorandom sequence is srand, which seeds G'MIC's random number generator. Given that the random number generator is completely deterministic, feeding it a particular seed will start it off on a particular sequence and that sequence always follows from that particular seed. You can use the number that you feed to srand as an identifier for a particular plasma. That, and a particular scale value, gives rise to a pattern which alpha and beta can modify, but not entirely obliterate.
Among other things, this aspect of plasma furnishes a great way to investigate the effects of the various plasma parameters. Let's look at a range of beta's shall we?
gmic repeat 5 srand 123456 100,100,1,1 plasma[1] 1,'{$>}',6 done d append x n[1] 0,255 o[1] betatest.png
The one bit of Mysterious Notation in this pipeline, '{$>}', is one of G'MIC's many, many substitution expressions, this one representing the current value of an overarching repeat...done loop. Armed with this bit, it should be fairly clear that as we loop, 0, 1, 2, 3, 4, 5 and 6 are successively substituted for the '{$>}' expression – we are running the same plasma command with the same parameters, alpha 1, scale 6, except beta, which ascends from 0 to 6 with each loop. The other matter of note is the invocation of srand at the top of the loop, essentially conjuring up plasma number '123456', which broadly composes a particular plasma, varying only with the beta parameter. Armed with this technique you are free to investigate other parameters on your own.
Even the most experienced G'MIC scripter will save out a pretty plasma from time to time, only to find it turning out black in Gimp or other paint programs. Plasmas are datasets! Unless scale happens to be too large for a given image size, plasmas tend to have the same average as their input images. Should the input image be dark or black, then roughly half the pixels in the image will be 'blacker than black', so far as paint programs are concerned.
`Tis generally a good idea to insert display commands here and there and pay close attention to G'MIC's summary lines; in all likelihood, you will need to normalize the image before passing the results to the bitmap editor of your choice.
Plasma is both a rendering and a filtering command. If given an image, the command will blend and perturb it in one atomic operation, giving rise to results akin to applying noise to an image, and then blurring it.
But not quite akin to noise, as plasma, unlike noise, can exhibit structure at different scales and an enchanting ability to mimic traditional artistic processes, notably brush strokes on canvas. Of course, given that many traditional painters spend much of their time on developing their brush work, my association of such to mere randomness has now pretty much alienated all the traditionalists out there, leaving — oh what? — one or two digerati here and there. So now that the room has been cleared, lets look at some practical examples.
Tintern Abbey, Monmouthshire, Wales  
We change the color model to Huesaturationluminance and inject the same plasmagenerated pattern, '781123' in each of the channels, varying the parameters. Quite apart from the plasma command, we also adjust the hue, saturation and luminance range to obtain a low saturated color image compressed into the red, yellow, yellowgreen end of the color wheel. These machinations are reminiscent of the photographic Pictorialists of the early twentieth century. They played with darkroom chemistry, we play with bits. Similar ambitions, though.  gmic srand 781123 

One of the nice aspects of the multiscale noise of plasma, is the almost always interesting response that the anisotropic smoothing command gives when it tries to trace edges through the plasma. The two commands, plasma and smooth working in tandem give rise to a tremendous range of pseudo brushwork.We also made recourse to gradient , direction2rgb and friends to generate color accent edges, giving a sense of pseudodepth to our pseudo brush work. 
smooth 70,0,1.0,5.0,0.5,3,3,2,2,0 
Garry Osgood
Image: Tintern Abbey by NotFromUtrecht, Wikimedia Commons