Detecting and Enhancing Edges and Lines

The following methods let you detect and enhance edges and lines:

EdgeDetector method

Sharpen method

SpatialFilter method

IntensityDetect method

UnsharpMask method

The Sharpen method is designed specifically to emphasize the edges (shifts in intensity) in a bitmap. It is a high-level method that can be used alone for the desired effect.

The SpatialFilter method provides several predefined filters for detecting edges or lines. These filters can be used alone in applications, such as industrial inspection systems, that analyze images. They can also be used to create an image that is combined with the original to change the appearance of lines or edges.

Choosing a filter is a subjective, application-specific decision. The filters use standard algorithms, some of which have similar purposes. You may need to experiment with them to choose the appropriate filter for your application. The following is a summary of the available filters:

Filter

Purpose

Emboss

Creates an image with an embossed appearance. (This is used for artistic effect, but is listed here because it is one of the predefined filters.)

Gradient directional

Detects edges, starting from any of eight specified directions. All pixels not on the detected edges are changed to black.

Prewitt

Detects horizontal or vertical edges. All pixels not on the detected edges are changed to black.

Sobel

Detects horizontal or vertical edges. All pixels not on the detected edges are changed to black. (The usage is the same as Prewitt, but the algorithm is different.)

Shift-and-difference

Detects horizontal, vertical, or diagonal edges. All pixels not on the detected edges are changed to black.

Laplacian

Detects lines. There are three omnidirectional filters and three bi-directional ones. All pixels not on the detected lines are changed to black.

Line-segment

Detects line segments. Possible directions are horizontal, vertical, left-to-right diagonal, and right-to-left diagonal. You can use this filter to find line discontinuities in an image. All pixels not on the detected line segments are changed to black.

To overcome the directional limitations of these filters, you can combine images that have been filtered in different ways. For example, you could make three copies of a bitmap, filter each one with a different Laplacian directional filter, and use the Combine method to create a bitmap with all of the detected lines. You could then combine this resulting bitmap with the original to enhance the lines in the original. For more information on combining images, refer to Combining Images.

The IntensityDetect method does not use a filter to detect edges or lines, but for some images it is more effective than the filters in detecting lines that are lighter or darker than other parts of the image.

The ContourFilter method applies a contour segment filter to the bitmap, creating a "contour map" of the bitmap.