Example Image Pyramid
From BoofCV
Jump to navigationJump to search
Image Pyramid Example
Image pyramids are a common way to represent multi-resolution image information. In an image pyramid, upper layers are lower resolution versions of the lower layers. BoofCV provides two types of image pyramids built in; PyramidDiscrete and PyramidFloat. PyramidDiscrete only allows the ratio between adjacent to have positive integer values, while PyramidFloat allows any arbitrary positive value. Discrete pyramids are much faster than float pyramids, but much more restrictive.
Two code examples are provided below which demonstrate how to work with each type of pyramid.
Example Code:
- ExamplePyramidDiscrete.java
- WRITE FLOAT EXAMPLE
Concepts:
- Multi-resolution image processing
- Discrete Vs. Float pyramids
- Image scaling
Relevant Applets:
Image Pyramid Discrete
/**
* Demonstrates how to construct and display a {@link PyramidDiscrete}. Discrete pyramids require that
* each level has a relative scale with an integer ratio and is updated by sparsely sub-sampling. These
* restrictions allows a very quick update across scale space.
*
* @author Peter Abeles
*/
public class ExamplePyramidDiscrete<T extends ImageBase> {
// specifies the image type
Class<T> imageType;
// The pyramid data structure
PyramidDiscrete<T> pyramid;
// update the pyramid given from
PyramidUpdaterDiscrete<T> updater;
public ExamplePyramidDiscrete(Class<T> imageType) {
this.imageType = imageType;
}
/**
* Creates a fairly standard pyramid and updater.
*/
public void standard() {
// Each level in the pyramid must have a ratio with the previously layer that is an integer value
pyramid = new PyramidDiscrete<T>(imageType,true,1,2,4,8);
// In most cases sub-sampling with a Gaussian is preferred
updater = FactoryPyramid.discreteGaussian(imageType,-1,2);
}
/**
* Creates a more unusual pyramid and updater.
*/
public void unusual() {
// Note that the first level does not have to be one
pyramid = new PyramidDiscrete<T>(imageType,true,2,6);
// Other kernels can also be used besides Gaussian
Kernel1D kernel;
if(GeneralizedImageOps.isFloatingPoint(imageType) ) {
kernel = FactoryKernel.table1D_F32(2,true);
} else {
kernel = FactoryKernel.table1D_I32(2);
}
updater = new PyramidUpdateIntegerDown<T>(kernel,imageType);
}
/**
* Updates and displays the pyramid.
*/
public void process( BufferedImage image ) {
T input = ConvertBufferedImage.convertFrom(image,null,imageType);
updater.update(input,pyramid);
DiscretePyramidPanel gui = new DiscretePyramidPanel();
gui.setPyramid(pyramid);
gui.render();
ShowImages.showWindow(gui,"Image Pyramid");
}
public static void main( String[] args ) {
BufferedImage image = UtilImageIO.loadImage("data/standard/barbara.png");
ExamplePyramidDiscrete<ImageFloat32> app = new ExamplePyramidDiscrete<ImageFloat32>(ImageFloat32.class);
// ExamplePyramidDiscrete<ImageUInt8> app = new ExamplePyramidDiscrete<ImageUInt8>(ImageUInt8.class);
app.standard();
// app.unusual();
app.process(image);
}
}
Image Pyramid Float
NEED TO WRITE THIS