ImageGear .NET
Device Independent Bitmap (DIB) and Region of Interest (ROI)

This topic provides information about the following:

Device Independent Bitmap (DIB)

Image data (or simply, image) is available for manipulations through the DIB property and is a ImGearDIB Class type. Color space, channels, width, and height are major attributes which define image structure.

ImageGear .NET considers an image as a collection of channels, each of which gives some single piece of information about the pixels in a whole image. Channels are defined as an array of depths for each channel. Depth specifies the quantity of different values for a particular channel. This data is constant for the page until image processing functions are applied. It may be accessed through the ImGearDIB.ChannelDepths Property.

The ImGearColorSpace Structure (returned by the ImGearDIB.ColorSpace Property) defines the semantics of the information stored in all channels (i.e., whether the second channel is the green component of RGB color, magenta of CMYK, or alpha value of a grayscale image). This information may be formed from ImGearColorSpaceIDs Enumeration flags and placed into the constructor of ImGearPage Class.

Pixels in ImGearDIB Class may be accessed as both individual pixels or groups of pixels. GetPixelCopy Method() and UpdateColumnFrom Method() are examples of such members. An important issue is that all of these routines return copies of the data stored in an image as an array of the ImGearPixel Class. None of these members allows direct access to the pixel store.

To gain direct access to an image, GetImage Method() or GetRaster Method() members of ImGearDIB Class should be used. This is an efficient way to implement image processing routines, since all changes made to the structures (returned by these functions) will be reflected in the image. Users of GetImage Method() or GetRaster Method() should completely understand the structure of the internal pixel store to avoid producing ill-formed images.

The following example creates an RGB image and swaps red and blue channel values for diagonal pixels: 

C#
Copy Code
using ImageGear.Core;

public void SwapRedAndBlueChannels()
{
   const int redChannel = 0;
   const int blueChannel = 2;

   // Create a 200x200, RGB 24-bpp image consisting of three, 8-bpp color channels.
   ImGearPage igPage = new ImGearRasterPage(200, 200,
                    new ImGearColorSpace(ImGearColorSpaceIDs.RGB),
                    new int[] { 8, 8, 8 }, true);

   // Iterates all rows in created page. 
   for (int row = 0; row < igPage.DIB.Height; row++)
   {
        // Obtains reference to raster store. 
        ImGearArrayRef igArrayRef = igPage.DIB.GetRaster(row);

        // Casts pixel data content to byte[] since all color channels are 8-bpp bit. 
        byte[] raster = (byte[])igArrayRef.Content;

        // Offset of diagonal pixel in raster. 
        int offsetToDiagonalPixel = igArrayRef.Offset + row * igPage.DIB.ChannelCount;

        // Swaps red & blue. 
        byte red = raster[offsetToDiagonalPixel + redChannel];
        raster[offsetToDiagonalPixel + redChannel] = raster[offsetToDiagonalPixel + blueChannel];
        raster[offsetToDiagonalPixel + blueChannel] = red;
    }
}
VB.NET
Copy Code
Imports ImageGear.Core

Public Shared Sub SwapRedAndBlueChannels()
        Const  redChannel As Integer = 0
        Const  blueChannel As Integer = 2

        ' Create a 200x200, RGB 24-bpp image consisting of three, 8-bpp color channels.
        Dim igPage As ImGearPage = New ImGearRasterPage(200, 200, New ImGearColorSpace(ImGearColorSpaceIDs.RGB), New Integer() {8, 8, 8}, True)

        ' Iterates all rows in created page. 
        For row As Integer = 0 To igPage.DIB.Height - 1
                ' Obtains reference to raster store. 
                Dim igArrayRef As ImGearArrayRef = igPage.DIB.GetRaster(row)

                ' Casts pixel data content to byte[] since all color channels are 8-bpp bit. 
                Dim raster As Byte() = DirectCast(igArrayRef.Content, Byte())

                ' Offset of diagonal pixel in raster. 
                Dim offsetToDiagonalPixel As Integer = igArrayRef.Offset + row * igPage.DIB.ChannelCount

                ' Swaps red & blue. 
                Dim red As Byte = raster(offsetToDiagonalPixel + redChannel)
                raster(offsetToDiagonalPixel + redChannel) = raster(offsetToDiagonalPixel + blueChannel)
                raster(offsetToDiagonalPixel + blueChannel) = red
        Next
End Sub

Region of Interest (ROI)

Region of interest (ImGearROI Class) represents a free-shape image area (rectangular, non-rectangluar, or entire space) and specifies a meaningful part of an image. For example, a region of interest may be established to define an area where some image processing functions should be applied.

 

 


©2017. Accusoft Corporation. All Rights Reserved.

Send Feedback