node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

pyramids

Pyramids

Image pyramids give a (slightly) overcomplete multiscale representation of an image, based on a reduce operator that reduces the size of an image by a factor of two (note though that conventionally, level 0 is the original scale, and higher levels correspond to smaller sizes). Example usage:

var pyramid = require("pyramids")
var ndarray = require("ndarray")
 
var p = pyramid(ndarray(new Int32Array([11,10,6,12,3,2,15,9,4,5,14,7,13,8,1]), [3,5]), pyramid.adjunction)

The above computes a pyramid using erosion (local minima, in this case within each 2-by-2 block), of the following "image" (array):

11106123
215945
1471381

The result is a list of ndarrays, with the first array (corresponding to level 0) being the original ndarray object. The array at level 1 is given by:

243
781

require("pyramids")(array, scheme[, maxlevel])

Returns a list containing array, followed by maxlevel (higher) levels of a pyramid based on the reduce operator of scheme (each an ndarray with the same type of data storage as array). If maxlevel is unspecified, it returns as many levels are necessary to end up with an array containing just one element. Note that the first level is simply the argument given to the function.

There is no restriction on the dimensionality of array, but a typed array must be used for storing the data in array (otherwise the pool allocator used internally will fail).

require("pyramids").detail(array, scheme[, maxlevel])

Same as require("pyramids"), but generates a detail pyramid. That is, all but the last level have been generated by expanding the next level and subtracting it from the current level.

require("pyramids").reconstruct(detailPyramid, scheme)

Reconstructs an image from a given detail pyramid (as output by the detail function). The reconstruction is done in-place. For example:

var pyramid = require("pyramids")
var p = pyramid.detail(ndarray(new Int32Array([11,10,6,12,3,2,15,9,4,5,14,7,13,8,1]), [3,5]), pyramid.adjunction)
// do something with the detail pyramid 
pyramid.reconstruct(p, pyramid.adjunction)
// p now contains a normal pyramid (with the first level corresponding to the full resolution reconstructed image) 

Morphological pyramids

Non-linear pyramids based on reduce and expand operators that satisfy the so-called pyramid condition: first expanding an image and then reducing it recovers the original image.

require("pyramids").adjunction

The adjunction pyramid has a reduce operator based on erosion, as described in

Nonlinear multiresolution signal decomposition schemes — Part I: Morphological pyramids ''IEEE Transactions on Image Processing'', Vol. 9, No. 11. (November 2000), pp. 1862-1876, doi:10.1109/83.877209 by John Goutsias, Henk J. A. M. Heijmans.

The structuring element used here is a (flat) 2-by-2 square in 2D, and in general a hypercube with sides of length 2. The expand operator uses the dilation that forms an adjunction with the erosion.

require("pyramids").SunMaragos

The SunMaragos pyramid has an opening (rather than an erosion) as reduce operator. The same structuring element is used as in the adjunction pyramid, based on the results in

A New Class of Morphological Pyramids for Multiresolution Image Analysis In Geometry, Morphology, and Computational Imaging, Vol. 2616 (2003), pp. 165-175, doi:10.1007/3-540-36586-9_11 by Jos B. T. M. Roerdink edited by Tetsuo Asano, Reinhard Klette, Christian Ronse.

This pyramid tends to preserve more of the image than the adjunction pyramid. However, the same expand operator is used as for the adjunction pyramid. Note that (according to Goutsias and Heijmans, 2000) Sun and Maragos originally used a different structuring element (of length 3).

Linear pyramids

Non-linear pyramids based on reduce and expand operators that satisfy the so-called pyramid condition: first expanding an image and then reducing it recovers the original image.

require("pyramids").binomial

This is a very basic pyramid that is not ideal for all purposes. However, it is essentially equivalent to the traditional Gaussian pyramid, and the Laplacian pyramid if a detail pyramid is computed. It uses a binomial filter ([1,4,6,4,1]/16) with the reduce and expand operators defined here:

The Laplacian Pyramid as a Compact Image Code ''IEEE Transactions on Communications'', Vol. 31, No. 4. (April 1983), pp. 532-540, doi:10.1109/tcom.1983.1095851 by Peter J. Burt, Edward H. Adelson