Rasters and Filtering
Insight3D provides a flexible Raster framework and raster processing through RasterFilters. A raster consists of one or more RasterBands, or sets of values, which are most commonly associated with colors when the raster represents an image. For instance, a typical color image contains three RasterBands (red, green, and blue) which define the color of pixels within the image. The following raster image formats can be read by the Raster class: BMP, ECW, IMG, JP2, NTF, NITF, PNG, SID, TIF, TIFF, JPG, JPEG, PPM, PGM, CLDS, and TGA. A raster can be loaded from a file, HTTP, HTTPS, or FTP source, can also be loaded from memory, or constructed from a BufferedImage.
The following code sample loads a raster from a URI:
Raster raster = new Raster(baseUri.resolve("Terrain%20and%20Imagery/colors.jp2"));
System.out.println(raster.getAttributes().getFormat()); System.out.println(raster.getAttributes().getType()); System.out.println(raster.getAttributes().getWidth()); System.out.println(raster.getAttributes().getHeight()); System.out.println(raster.getAttributes().getRowStride());
To create a texture from a raster, pass it to the fromRaster method.
Texture2D texture = SceneManager.getTextures().fromRaster(raster);
The RasterFilter base class allows a user to perform many image processing tasks. The following filters are provided:
BrightnessFilter - adjust brightness
ContrastFilter - adjust contrast
LevelsFilter - adjust color levels
GammaCorrectionFilter - perform gamma correction
BandExtractFilter - extract bands
BandOrderFilter - reorder bands
ConvolutionFilter - generic convolution with a kernel
SharpenFilter - sharpening
EdgeDetectFilter - edge detection
GradientDetectFilter - gradient detection
SequenceFilter - apply a sequence of filters
In the following code sample, contrast, brightness, and gamma correction filters are initialized and applied sequentially to a satellite image to improve its visibility. The applyInPlace method will apply a filter to a raster directly. Alternatively, the apply method will leave the original raster intact and return a new raster with the results of the filtering.
// Add brightness, contrast, and gamma correction filters to sequence SequenceFilter filter = new SequenceFilter(); filter.add(new BrightnessFilter(0.3)); filter.add(new ContrastFilter(0.5)); filter.add(new GammaCorrectionFilter(0.9)); raster.applyInPlace(filter);
ConvolutionFilter is a very generic filter which can be used for a much larger variety of effects. In the following code sample, a custom convolution filter is applied to sharpen the color-corrected imagery above.
// Apply a convolution matrix to sharpen the Raster ConvolutionFilter convolutionFilter = new ConvolutionFilter(); convolutionFilter.setKernel(new Matrix3By3(0.0, -1.0, 0.0, -1.0, 5.0, -1.0, 0.0, -1.0, 0.0)); raster.applyInPlace(convolutionFilter);
See the HowTo for a variety of additional raster and filtering examples.