-dct and -idct

Figure 1: In that fleeting instant before the analysis transform, the Integer Kid glared at his mirrored, odd columns straight in their eye.

The Discrete Cosine Transform and Inverse Discrete Cosine Transform are functional work-a-likes of the Discrete Fourier Transform (-fft) and Inverse Discrete Fourier Transform (-ifft).

The format of the commands are identical to -fft and -ifft:

-dct { x | y | z }..{ x | y | z } |

The commands take a single string consisting of combinations of the letters 'x', 'y' and 'z.'  If present, this string argument restricts the transform to just those cited axes.

A dataset nominally of a particular dimension may be evaluated as a collection of lower-dimensioned datasets. For example, with the argument 'xy', a pair of single channel images with dimensions 256,256,256,1, nominally a three dimensional field, may be viewed as a sequence of 256 two dimensional fields. Each z-increment indexes a two dimensional 'xy' dataset which is transformed independently of the others.

Similarly a pair of 256,256,1,1 single channel images on the image list can be processed as 256 one dimensional datasets. 'x' indicates a row-by-row organization, 'y' indicates column-by-column.

The practical advantage of this pair of commands over -fft and -ifft may be found in images, which commonly do not consist of complex number data sets. The Discrete Cosine Transform operate on real data and produce real data, so a fiat imaginary is unnessary.

Data Reflection

The command exploits a property of images which are symmetrical across an axis, exhibiting mirror symmetry, such as a wine glass across the vertical axis. The Fourier Analysis Transform of such images have a zero imaginary component, which can be then disregarded.

Images do not typically exhibit symmetry across any axis, however. That said, the necessary condition can be approximated by separating an image into odd and even columns (or rows), mirroring one set and then appending the sets together as in Figure 1.

Reflecting an image upon itself is not difficult with G'MIC; the technique illustrates the versatility of the language's selection syntax in conjunction with creating a local environment:

gmic -input integerkid.jpg  # Fetch any sort of image. \
 -split[-1] x  # turns one image into a large series of one column images\
 -local[1--1:2]  # The selection pulls into a local environment only the odd-numbered columns \
  -append x  # Only the odd-numbered single column images are visible in the local environment. The local environment now has one image of only the odd numbered columns. \
  -mirror x  # Mirrors the odd-column-only image about the x axis. \
 -endlocal  # Releases the local environment back into the overall image list. \
 -mv[1] [-1]
 # Shifts the odd-columns-only image to the end of the image list. \
 -append x
 # Appends the even-columns-only into the left half of the image; appends the odd-columns-only image into the right half. \

The one dimensional transforms along rows will give rise to imaginary data that will be very nearly zero. The same separation and mirroring process then takes place along columns and the one dimensional transform along columns also gives rise to imaginary data very near zero. One may ignore these very nearly zero imaginary data and spectrally edit just the real components.

Garry Osgood