Trigometric And Inverse Trigometric Commands

The trigometric commands, -sin, -cos, and -tan interpret channel intensities of pixels as angular radian measures and translate these values, respectively, to sine, cosine or tangent quantities. None take additional command line parameters.

For example, we may generate a ramp image with pixel intensities ranging from zero to 4*π. -sin replaces each pixel in this image, i, with sin(i):

gmic 200,200,1,1,4*pi*x/w --sin[-1] -output[-1]sine.cimg

Next, we can replace each pixel, sin(i) with its trigometric inverse, asin(sin(i)).

gmic -input sine.cimg -asin[-1] -output asine.cimg

This generates a sawtooth wave instead of restoring the original ramp, as the trigometric functions are periodic, mapping perodic series from the input to single output values. For example,  π/2, 5π/2, 9π/2... all evaluate to unity under the trigometric sine function. The inverse trigometric functions have no way of knowing whatever periodic multiplicity may have been in the original data, so map input values to a single, primary range. 

Ramp image autogenerated on the command line. It ranges in intensity from zero (left) to 4*π (right). After the -sin command operated on the image to the left, and saved as sine.cimg. It ranges in intensity from -1 (black) to 1 (white). In essence, it treated each pixel in the image on the left as an angular measure in radians and converted the pixel to the corresponding sine value. After the inverse trigometric command, -asin[-1]  operated on the sine wave image to the left, a sawtooth wave resulted. It treated pixels in the image on the left as sine values and converted each pixel to a radian measure in the range −π/2 to π/2. A set of intensity graphs from the middle horizontal line taken from each of the three images on the left (click on the graph for a larger version).


Both the -sin and -cos commands may be harnessed to highlight small variations in data. The gradient backgrounds at the beginning of the walkthrough, below, are meant to be composited into successive animation frames. Some shimmer was seen in this background during a test run,  though the gradients seem innocent of any wrongdoing.

We scale the intensity of these gradients up to a high multiple of pi, so that the -sin (or -cos) commands can translate the extended range into a large number of cycles, each having short wavelengths, a few tens of pixels each. If the original images are identical, so would be the cyclic patterns generated by the trigometric functions. Overlaying one translated background on top of the other would show no misalignment of cyclic patterns. However, a variation between gradients, hard to perceive in the originals, would be reflected in a mismatch of cyclic patterns as differences in intensities in a particular locale would be reflected in wave patterns shifting to different places. The pattern misalignment would be manifestly obvious, given the short wavelength patterns. Details follow.


gmic -input sheen.png -input sheen_2.png --luminance -normalize 0,{30*pi} \
--sin[-2,-1] -append[-2,-1] c -normalize[^0,1] 0,255 -display -output[^0,1] sheen_o.png



These two frames, sheen.png and sheen_2.png seem identical at first glance, though studied observation over time will reveal differences. This walkthrough will render such differences quickly an unambiguously.  


gmic -input sheen.png -input sheen_2.png --luminance -normalize 0,{30*pi}...

We convert the frames to grayscale and normalize them to the range of zero to thirty times pi. After processing by either -sin or -cos, fifteen complete cycles, of about thirteen pixels each cycle, will span each image. The precise locations of these cycles depend upon the intensity of the image and variations in such between the two images will become manifest by misalignment of cycles. Given the narrow wavelength, even a small variation between the two frames will be distinctly obvious.


...--sin[-2,-1] -append[-2,-1] c -normalize[^0,1] 0,255 -display...

We overlay the two images by moving them into the channels of one image, specifically, by appending two images along the 'spectral direction'. It is clear from the misalignment of the cycle pattern that the two gradients are not exactly the same. The distortion pattern can even tell us by how much the gradients can differ. Fifteen cycles across two hundred pixel images give rise to about 13 pixels per cycle. About halfway down and a third of the way from the left, the displacement appears to be as much as one cycle, or thirteen pixels. The lefthand gradient in panel two corresponds to channel 0 (red) in the test image to the left, while the righthand gradient in panel two corresponds to channel 1 (green), this, the order these two patterns occupied on the image stack when the append command was invoke. Armed with this knowlege, the straight red pattern indicates that the first gradient changes exactly in the x direction only at a constant rate, for the cycles do not vary from the vertical. They do so in the green test pattern, however - the variation from black to white is non-linear.

Garry Osgood