There are some things that you can do to optimize the edge extraction and/or speed up the calculation process:
Specify an area to process.
Perform post-calculations to calculate expensive features.
Optimize your control type (MedgeControl()) settings.
Retrieve calibrated results in world units.
Specify an area to process that contains all necessary edges. You can specify an area using a child buffer. All edgels that fall outside the area will be ignored, speeding up the edge extraction. For non-rectangular areas, you can specify the appropriate area using a mask (MedgeMask()).
For more information on setting an area, see the Using child buffers, ROIs, or a copy to manipulate specific data areas section of Chapter 21: Data buffers, or the Masking the edges subsection of the Advanced edge extraction section earlier in this chapter.
To compute features as efficiently as possible, you should calculate a few features first (preferably, the fastest), and eliminate as many unnecessary edges as possible. Then, post-calculate expensive features on the remaining edges. The process of calculating features and eliminating unnecessary edges can be repeated until the required result is calculated. Post-calculation greatly decreases processing time since MIL won't have to calculate the most time-consuming edge features for all edges.
For more information on post-calculation, see the Post-calculation subsection of the Calculating and retrieving results section earlier in this chapter.
To compute features as efficiently as possible, you should optimize your MedgeControl() control type settings. Some settings result in faster calculations (MedgeCalculate()). Note that faster calculations do not mean better results and your application might require settings that take longer to calculate.
Use the minimum required accuracy (M_ACCURACY); decreasing the accuracy increases the speed of the calculation process. Disabling M_ACCURACY results in pixel precision, which although not very precise, is typically sufficiently accurate when extracting the edges of large objects. By default, the accuracy is set to M_HIGH; this results in subpixel edgel accuracy, but typically a slower calculation process.
For more information on setting the accuracy, see the Edgel accuracy subsection of the Customizing the edge extraction settings section earlier in this chapter.
If possible, reduce the detail level of edge chains by disabling M_CHAIN_ALL_NEIGHBORS. Disabling this control type increases the speed of the calculation but reduces the level of detail present in the edge chains. Enabling this control type results in slower calculations; however, the edge chains contain the most amount of edgel information possible. Note that by default, this control type is disabled.
For more information on edge chains, see the Basics of edge extraction subsection of the Extracting the edges section earlier in this chapter.
If possible, reduce the scale of the image when extracting edges, by setting M_EXTRACTION_SCALE to a value between 0.0 and 1.0. Reducing the extraction scale can increase the speed at which edges are found and extracted. Note however, this can result in less reliable results, including the loss of important details and/or reduced accuracy of the extraction results. An extraction scale greater than 1.0 will slow down the extraction. Once the edge extraction is complete, the results are scaled to the original scale of the image. Note that the default setting of 1.0 usually provides the most accurate search results.
When using an IIR filter, it is generally faster to implement the filtering operation recursively, unless you implement it using kernel mode with a very small convolution kernel (for example, 3x3). If you use kernel mode with a large kernel, the calculation will be slower, although more accurate. Note that if you have dedicated hardware performing the operation, it is typically faster to use a convolution kernel.
For more information on filters, see the Customizing the edge extraction settings section earlier in this chapter.
If your image contains a lot of noise, increase the smoothness factor (M_FILTER_SMOOTHNESS). Increasing the smoothness factor reduces the noise, resulting in the edge extraction operation extracting fewer unwanted edges. This will typically decrease the time it takes to extract the edges. Be aware that in kernel mode, increasing the smoothness factor can increase the size of the convolution kernel, which increases the processing time. Note that a very high smoothing level can result in a loss of important detail and a decrease in precision.
For more information on specifying the smoothness factor, see the Smoothing for IIR filters subsection of the Customizing the edge extraction settings section earlier in this chapter.
Use the square of the gradient magnitude, by setting M_MAGNITUDE_TYPE to M_SQR_NORM. This optimizes the edge extraction while preserving a very good edgel result. M_SQR_NORM is calculated faster than M_NORM, but is less accurate. Note that for M_MAGNITUDE_TYPE, the default is M_SQR_NORM for contour Edge Finder contexts, and the default is M_NORM for crest Edge Finder contexts.
For more information on the magnitude type, see the Magnitude type subsection of the Customizing the edge extraction settings section earlier in this chapter.
Use the highest possible threshold (M_THRESHOLD_MODE) that still detects all pertinent edgels. The lower the threshold, the more sensitive the edgel detection; that is, more edgels are detected. The default threshold mode is M_HIGH.
For more information on thresholding, see the Thresholding subsection of the Customizing the edge extraction settings section earlier in this chapter.
Calculate the length of each edge using M_FAST_LENGTH. M_FAST_LENGTH gives a coarser but faster approximation of the edge's length than M_LENGTH.
For more information on calculating the length, see M_FAST_LENGTH and M_LENGTH in MedgeControl().
When retrieving the coordinates of edgels using MedgeGetNeighbors(), limit the search region using M_SEARCH_RADIUS_MAX, M_SEARCH_RADIUS_MIN, and M_SEARCH_ANGLE_TOLERANCE. All edgels that fall outside this region will be ignored, speeding up the edge extraction.
For more information on setting the search radius, see the Location-based constraints subsection of the Advanced edge extraction section earlier in this chapter.
If your image is calibrated, retrieve results in world units. Retrieving results in pixel units will typically be slower. Also note that, in the presence of distortion, some results are meaningless when converted from real-world to pixel units (for example, the Feret angles).
For more information, see the Camera calibration - overview section of Chapter 26: Calibrating your camera setup.