Most image processing functions act on a bitmap in memory, which means that the changes become permanent when you save the image in a file. Some low-level functions act on a buffer that you manage (for example, when you process data as it is loaded).
You can change the color resolution (bits per pixel) of an image using a number of high-level and low-level functions. For a list of these functions, refer to Doing Color Expansion or Reduction.
Windows always uses the RGB color-space model, and when loading or saving a file, LEADTOOLS converts image data to or from RGB, as necessary. Nevertheless, LEADTOOLS provides functions for other color-space models. You can use the high-level L_ColorSeparateBitmap and L_ColorMergeBitmap functions to create and merge color separations using a number of color-space models, including RGB, CMYK, CMY, HSV, and HLS. You can also use the low-level L_ConvertColorSpace function to convert raw data in a buffer from one color-space model to another, including RGB, YUV, CMYK, CMY, YIQ, HSV, and HLS.
If the source data is in the YUV colorspace rather than in BGR/RGB format, you can use the L_SetBitmapYUVData function to convert the YUV data to grayscale/BGR before being set in the BITMAPHANDLE. Use the L_GetBitmapYUVData function to convert a bitmap's grayscale or BGR data to YUV and store it in an output buffer.
The L_AutobinarizeBitmap automatically converts color images into binary (black and white) images, with several pre-processing options. These include eliminating the bitmap's background, (while keeping key features such as text); performing automatic color-leveling, and performing color-leveling with user-specified thresholds.
Image data can be changed from signed to unsigned and vice versa. Signed image data may contain some negative values. Converting data from signed to unsigned, and vice versa, is done by shifting the image data/intensity values by a specific value. The ability to shift image data back and forth between signed and unsigned is often useful in medical or analytical applications.
To change image data from signed to unsigned, which is often done before applying image processing or analysis functions, there are the following options:
L_ConvertBitmapUnsignedToSigned shifts the image data based on internal aspects of the bitmap.
L_ShiftMinimumToZero provides the user with the value by which the image data was shifted. This information can be used later, after image processing, to return the image to signed data.
L_ClearNegativePixels sets all negative pixels to 0, therefore creating an unsigned image.
After signed images have been converted to unsigned images image processing or analysis functions can be performed on the unsigned images. (Most image processing functions work only on unsigned data.) When the image processing or analysis is complete, convert the unsigned data back to signed data.
To change image data from unsigned to signed, which is often done after applying image processing or analysis functions, there are the following options:
L_ConvertBitmapSignedToUnsigned shifts the image data based on internal aspects of the bitmap.
L_ShiftZeroToNegative gives the user the ability to specify the amount by which to shift the image data, and dictates the minimum and maximum values that are output by the function.
Geometric transformations include resizing, trimming, rotating, shearing, flipping, or reversing a bitmap. Some geometric transformation functions are designed mainly for document imaging. For example, L_DeskewBitmap (Document and Medical Imaging toolkits ) and L_DeskewBitmapExt(Document and Medical Imaging toolkits ) let you automatically straighten scanned documents. L_DeskewBitmap has special flags that make it possible to straighten bank check images. For more information, refer to Deskewing.
LEADTOOLS also provides the L_TransformFile function for performing lossless flips, rotations and reversals. However, only certain file formats are supported at this time. This function provides better results than loading an image, transforming it using L_RotateBitmap, L_FlipBitmap or L_ReverseBitmap and then resaving it. It uses the TRANSFORMFILECALLBACK function for processing the file. The TRANSFORMFILECALLBACK function in turn uses the LEADMARKERCALLBACK function for writing any updated markers within the file. For more information, refer to L_TransformFile, TRANSFORMFILECALLBACK and LEADMARKERCALLBACK.
The L_DisplaceMapBitmap function displaces bitmap pixels horizontally and vertically according to the values of the displacement map image.
The L_PerspectiveBitmap function gives a bitmap a 3-D depth, as if it exists on a flat plane and has been skewed into a different shape. The L_ManualPerspectiveDeskew function corrects the view perspective.
The L_Keystone function maps a polygon to a rectangle (an inverse perspective transformation), and can be used to correct the perspective of images that were captured from portable devices at an angle.
The L_UnWarp function removes the distortion in an image of a cylindrical object, as if removing a label from off of the cylinder and flattening it out.
Use the L_BezierPath function to match the output curve with the curve between two corners of the shape before calling L_UnWarp. Be sure to call L_FreeBezierPath when finished in order to free all the memory associated with the structure.
The L_AlignImages function aligns two images (the pRefBitmap and pTempBitmap images) based on the locations of the input points. The images are combined, creating the ppOutBitmap image.
For a list of functions in this group, refer to Raster Image Functions: Doing Geometric Transformations. For information about memory allocation when a bitmap gets bigger, refer to Resizing Considerations.
A number of image processing functions let you change the values of pixels across a bitmap (or a region in the bitmap) using various algorithms and filters. You might do this to improve the appearance of the image, to analyze details in the image, or to apply artistic effects. The following topics provide details:
The L_CombineBitmap function lets you add all or part of another bitmap to the target bitmap. You can pass flags to control whether the new pixels simply replace the old ones or are combined with the old ones in a specified way. You can also define regions in either or both of the bitmaps, and if you do, the function affects only the intersection of the regions. The L_CombineBitmap also lets the user combine bitmaps of different bits per pixel and specify which color planes to use when combining the bitmaps. For information about regions, refer to Defining and Using a Bitmap Region.
Source and destination bitmaps may be combined by warping all or part of a source bitmap into part of a destination bitmap. To combine images in this manner, use L_CombineBitmapWarp.
The L_UnderlayBitmap function also combines images, but it has a much more specific purpose. It combines two bitmaps so that one appears to be an underlying texture for the other.
LEADTOOLS provides several functions for picturizing an image. The L_PicturizeBitmap function replaces an image with a new image created by combining images present in a specific directory. L_PicturizeBitmapList replaces an image with a new image created by combining images present in a bitmap list. The L_PicturizeBitmapSingle function picturizes an image using various versions of a single image.
Two bitmaps can also be blended by combining the images with an opacity value. The L_AlphaBlendBitmap function combines two bitmaps with a fixed opacity value to create a new blended image. The L_FeatherAlphaBlendBitmap function combines two bitmaps with feathering by using a variable opacity that depends on a fade mask with specifying the region of the fade mask. A fade mask bitmap can be created using the L_CreateFadedMask function.
The L_BumpMapBitmap function lets you combine a bitmap with a bump image to create a three-dimensional texture pattern.
The L_CanvasBitmap function applies an image as an overlay for another image.
A number of other functions let you get and put pixel data. For example, you can fill a bitmap with a color, and you can get and put individual pixel values. For a list of functions, refer to Getting and Setting Pixel Values.
Treating the bitmap as a device context opens up many possibilities. The L_CreateLeadDC function lets you get the device context. You can then use Windows GDI functions to draw lines, text, or images on the bitmap. You can also use the LEADTOOLS special effects functions to add three-dimensional shapes or text, or to combine images in interesting ways. For details, refer to Implementing Special Effects.
L_TextureAlphaBlendBitmap combines image data from pBitmapMask and pBitmapUnderlay with an underlay effect. The result is used as a fade mask that will be used to combine pBitmapSrc and pBitmapDst with variable opacity. The result is combined again with pBitmapDst using a constant opacity (using nOpacity). The L_BricksTextureBitmap function creates a brick texture that makes the image look like it has been drawn on a brick wall.
The L_DigitalSubtractBitmap function does not combine images, but subtracts the live (destination) bitmap from the mask (source) bitmap to show the differences between the two bitmaps.
Two bitmaps or parts of two bitmaps can be compared using the L_CorrelationBItmap function. This function compares all or part of one bitmap with all the areas of the same dimensions in another bitmap and finds those areas that match according to the measure of correlation. The L_CorrelationListBitmap function compares the images in hCorList with all the areas of the same dimensions in pBitmap and finds those portions that match according to the measure of correlation.
The L_SliceBitmap function is designed to extract the individual slices from radiographic scanned film.
The L_BlankPageDetectorBitmap function determines whether the scanned image is a blank page (empty) or not, also it gives the accuracy percentage of the result. This function helps in reducing disk storage of scanned images.
The L_InvertedPageBitmap function detects whether the image (page) is inverted (white text and black background). If it is inverted it is inverted again so the text is black and the background is white. Use this function to enhance OCR and clean-up function performance.
The L_LambdaConnectedness function performs image segmentation using a special region-growing algorithm called Lambda Connectedness.
The L_LevelsetBitmapRgn function performs semi-automatic segmentation (using the Levelset algorithm) to find the best-fitting contour that encapsulates the object.
The L_OtsuThreshold function performs image segmentation and color reduction using Otsu clustering on grayscale images. Otsu thresholding is typically used as a way to binarize an image.
Use the L_MICRDetection function to automatically detect Magnetic Ink Character Recognition (MICR) zones in a document image.
Use the L_MRZDetection function to automatically detect a Machine-Readable passport Zone (MRZ) in a document image.
The L_SignalToNoiseRatio function calculates the Signal To Noise Ratio (SNR) as the 10*log10 of the real value. This value gives an indication of the homogeneity of adjacent pixels in an image.
The L_KMeansBitmapSegmentation function is an algorithm for analyzing data. Each observation gets placed in the cluster having the mean nearest it.
The L_GWireGetMinPath function detects objects in an image using the G-Wire algorithm.
The L_AutoZoneBitmap function detects different zones (Text, Graphic and Tables) in an image automatically, and return the location (rectangle) and the data of each zone such as (text lines and table's cells ) in an allocated memory. It could be used with OCR, or any application that needs to automatically separate images, tables and text within mixed raster content (MRC) images.
If the user has defined an AUTOZONECALLBACK function and passed a pointer to this function to L_AutoZoneBitmap, the callback function will receive each zone detected. This allows the user to process each image as desired.
When the allocated memory that contains the detected zones is no longer needed, it should be freed by calling the L_FreeZoneData function.
Typically, the Magic Wand operation creates a Windows region or a LEAD region (L_RGN). Although the Fast Magic Wand operation works in the same manner and under the same conditions, it creates an OBJECTINFO structure containing two elements: a rectangle and a two-dimensional array.
The rectangle corresponds to the bounding box of the region. The two-dimensional array corresponds to the pixels belonging to that region by referencing included elements as 1 as opposed to 0 when they are not included.
The number, orientation and order of the elements of the two-dimensional array correspond to those pixels within the bounding rectangle. Thus, the exact shape and position of the region can be known.
To begin using the Fast Magic Wand operation, you must first initialize a Fast Magic Wand handle. This is done by calling the L_StartFastMagicWandEngine function. Once the handle is initialized, perform the fast magic wand operation by calling the L_FastMagicWand function. This function is used when it is needed to select many regions over one image, especially large images as it performs faster. When the OBJECTINFO structure obtained by the L_FastMagicWand is no longer needed, delete it by calling the L_DeleteObjectInfo function.
The L_ObjectCounter counts the objects in a binary image. It counts the black objects against a white background. If the background is black and the objects are white, use L_InvertBitmap and then use L_ObjectCounter.
When the fast magic wand handle is no longer needed, free the handle by calling L_EndFastMagicWandEngine. At this point this handle becomes invalid.