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 Bitmap.
The following code sample loads a raster from a URI:
Raster raster = new Raster(new Uri(baseUri, "Terrain and Imagery/colors.jp2"));
Once a raster is loaded, the defining RasterAttributes of the raster is available from the Attributes.
Console.WriteLine(raster.Attributes.Format); Console.WriteLine(raster.Attributes.Type); Console.WriteLine(raster.Attributes.Width); Console.WriteLine(raster.Attributes.Height); Console.WriteLine(raster.Attributes.RowStride);
To create a texture from a raster, pass it to the FromRaster method.
Texture2D texture = SceneManager.Textures.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 { Kernel = 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.