In This Topic ▼

Processing an Image

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.

Changing the Data Format

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 LBitmap::ColorSeparate and LBitmap::ColorMerge 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 LBuffer::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.

Changing the Data Type (Signed / Unsigned)

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, will be done by shifting the image data or 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:

Once 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:

Doing Geometric Transformations

Geometric transformations include resizing, trimming, rotating, shearing, flipping, or reversing a bitmap. Some geometric transformation functions are designed mainly for document imaging. For example, LBitmap::Deskew (Document/Medical) and LBitmap::DeskewExt(Document/Medical)  let you automatically straighten and trim scanned documents. LBitmap::Deskew (Document/Medical only) has special flags that make it possible to straighten bank check images. For more information, refer to Deskewing.

For resizing any kind of bitmap, LBitmapBase::Size and LBitmapBase::SizeInterpolate provides the most up-to-date options, but you may also find the alternative and low-level functions useful.

LEADTOOLS also provides the LFile::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 LBitmapBase::Rotate, LBitmapBase::Flip or LBitmapBase::Reverse and then resaving it. It uses the LFile::TransformFileCallBack function for processing the file. For more information, refer to LFile::TransformFile.

The LBitmap::DisplaceMap function displaces bitmap pixels horizontally and vertically according to the values of the displacement map image. The LBitmap::Perspective function gives a bitmap a 3-D depth, as if it exists on a flat plane and has been skewed into a different shape.

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.

Lightening, Darkening, Filtering, and So Forth

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:

Changing Brightness and Contrast

Removing Noise

Detecting and Enhancing Edges and Lines

Applying Artistic Effects

Correcting Colors

Getting or Setting Bitmap Information

Using the LBitmap::Perlin Function

Adding Another Image to a Bitmap

The LBitmapBase::Combine 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 LBitmapBase::Combine function also let the user to 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 LBitmapBase::CombineBitmapWarp.

The LBitmapBase::Underlay 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 LBitmap::Picturize function replaces an image with a new image created by combining images present in a specific directory. LBitmap::PicturizeList replaces an image with a new image created by combining images present in a bitmap list.

The LBitmap::PicturizeSingle function picturizes an image using various versions of a single image.

Borders and frames may be added to a bitmap using the LBitmap::AddBorder and LBitmap::AddFrame functions.

LBitmap::TextureAlphaBlend 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 LBitmap::BricksTexture function creates a brick texture that makes the image look like it has been drawn on a brick wall.

The LBitmap::Clouds function creates a cloud texture that can be saved by itself or combined with another image.

The LBitmap::DigitalSubtract function does not combine images, but subtracts the live (destination) bitmap from the mask (source) bitmap to show the differences between the two bitmaps.

The LBitmap::BumpMap function lets you combine a bitmap with a bump image to create a three-dimensional texture pattern.

The LBitmap::Canvas function applies an image as an overlay for another image.

Two bitmaps can also be blended by combining the images in a manner that is based on opacity. The LBitmapBase::FeatherAlphaBlend 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 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 LBitmapBase::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.

Comparing Images

Two bitmaps or parts of two bitmaps can be compared using the LBitmap::Correlation 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 LBitmap::CorrelationList function compares the images in hCorList with all the areas of the same dimensions in the bitmap image and finds those portions that match according to the measure of correlation.

Related Topics:

Color Halftones and Halftone Images

Deskewing

Extracting Bitmaps From A Series

The LBitmapBase::Slice function is designed to extract the individual slices from radiographic scanned film.

Detecting image features

The LBitmap::BlankPageDetector function determines whether the scanned image is a blank (empty) page or not, and provides the percentage accuracy of the result. This function helps in reducing disk storage requirements for scanned images.

The LBitmap::BlurDetection function determines whether an image is blurred.

The LBitmap::GWireGetMinPath function This function is useful for extracting objects from an image. It works by constructing a minimal path between two input points (the seed point and the target point) that follows the edges of the image's objects.

The LBitmap::GlareDetection function automatically finds the glare zone in an image.

The LBitmap::InvertedPage function detects whether the image (page) is inverted (white text and black background). If it is inverted it is inverted so the text is black and the background is white. Use this function to enhance OCR and clean-up function performance.

The LBitmap::KMeansBitmapSegmentation function is an algorithm for analyzing data. Each observation gets placed in the cluster having the mean nearest it.

The LBitmap::LambdaConnectedness function performs image segmentation using a special region-growing algorithm called Lambda Connectedness.

The LBitmap::LevelsetBitmapRgn function performs semi-automatic segmentation (using the Levelset algorithm) by shrinking or expanding a contour represented by a region to the objects in the image.

The LBitmap::MRZDetection function automatically detects a machine-readable passport (MRZ) zone in a document image.

The LBitmap::OtsuThreshold function performs image segmentation and color reduction using Otsu clustering on grayscale images.

The LBitmap::ShrinkWrapTool function automatically segments a rectangular or circular area in the specified image using the specified threshold.

The LBitmap::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 LBitmap::SRADAnisotropicDiffusion function is used to reduce noise and speckling in images while preserving the edges.

The LBitmap::TADAnisotropicDiffusion function is an iterative filter that performs Tensor-guided Anisotropic Diffusion (TAD) in order to reduce noise while preserving the edges in the image.

The LBitmap::WatershedBitmap function separates the image into different segments using the Watershed algorithm.

Magic Wand and Fast Magic Wand Operations

Magic Wand

The Magic Wand is an operation that creates a region by calling LBitmapRgn::SetRgnMagicWand function on an image by growing from a certain pixel and color tolerance both specified by the user.

The region would start from the specified pixel and expand its way in all directions under the condition that in each expanding step the color of the new pixel included must be within the color value or the original pixel +/- the color tolerance value.

Once a certain pixel exceeds that color range, the region growing would seize in that direction.

Fast Magic Wand

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 but it creates an OBJECTINFO structure containing two elements, a rectangle and a two dimensional array.

The rectangle would be the bounding box of the region, and the two dimensional array would correspond the pixels belonging to that region by referencing their elements as 1 as apposed 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, the user must initialize a fast magic wand handle. This is done by calling either the LBitmap::StartFastMagicWandEngine function. Once the handle is initialized, the user can perform the fast magic wand operation by calling LBitmap::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 obtained OBJECTINFO structure by LBitmap::FastMagicWand is no longer needed, it must be deleted by calling LBitmap::DeleteObjectInfo function.

The LBitmap::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 black, use LBitmap::Invert and then use LBitmap::ObjectCounter.

When the fast magic wand handle is no longer needed, the user must free the handle by calling LBitmap::EndFastMagicWandEngine. At this point this handle becomes invalid.

Changing the Data Format

Use Bitmap::AutoBinary when you simply want to apply binary segmentation to the bitmap using an automatically calculated threshold based on a two-peak method of statistical analysis on its histogram. Use Bitmap::DynamicBinary if you want to convert a bitmap into a black and white image without changing its bits per pixel by using a local threshold value for each pixel of the image. Use Bitmap::AutoBinarize if you want:

Auto Zoning (Detecting image features)

The LBitmap::AutoZone 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 tables 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 overriden an LBitmap::AutoZoneCallback function, 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 LBitmap::FreeZoneData function.

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.