Back to FabImage Library website

You are here: Start » Function Reference » Computer Vision » 1D Edge Detection » ScanExactlyNRidges


Header: FIL.h
Namespace: fil
Module: MetrologyBasic

Locates a specified number of the strongest dark or bright pixel peak along a given path.

Applications: Very fast detection (or presence verification) of thin structures like wires or scale marks.


void fil::ScanExactlyNRidges
	const fil::Image& inImage,
	const ScanMap& inScanMap,
	const RidgeScanParams& inRidgeScanParams,
	int inRidgeCount,
	fil::Selection::Type inRidgeSelection,
	float inMinDistance,
	ftl::Optional<float> inMaxDistance,
	ftl::Optional<const fil::LocalBlindness&> inLocalBlindness,
	ftl::Conditional<ftl::Array<fil::Ridge1D> >& outRidges,
	ftl::Conditional<ftl::Array<fil::Gap1D> >& outGaps,
	ftl::Optional<fil::Profile&> outBrightnessProfile = ftl::NIL,
	ftl::Optional<fil::Profile&> outResponseProfile = ftl::NIL


Name Type Range Default Description
Input value inImage const Image& Input image
Input value inScanMap const ScanMap& Data precomputed with CreateScanMap
Input value inRidgeScanParams const RidgeScanParams& RidgeScanParams ( ProfileInterpolation: Quadratic4 SmoothingStdDev: 0.6f RidgeWidth: 5 RidgeMargin: 2 MinMagnitude: 5.0f RidgePolarity: Dark ) Parameters controlling the ridge extraction process
Input value inRidgeCount int 0 - 1 Number of ridges to be found
Input value inRidgeSelection Selection::Type Selection::​Best Selection mode of the resulting ridges
Input value inMinDistance float 0.0 - 0.0f Minimal distance between consecutive ridges
Input value inMaxDistance Optional<float> 0.0 - NIL Maximal distance between consecutive ridges
Input value inLocalBlindness Optional<const LocalBlindness&> NIL Defines conditions in which weaker ridges can be detected in the vicinity of stronger ridges
Output value outRidges Conditional<Array<Ridge1D> >& Found ridges
Output value outGaps Conditional<Array<Gap1D> >& Gaps between consecutive edges
Output value outBrightnessProfile Optional<Profile&> NIL Extracted image profile
Output value outResponseProfile Optional<Profile&> NIL Profile of the ridge operator response

Optional Outputs

The computation of following outputs can be switched off by passing value ftl::NIL to these parameters: outBrightnessProfile, outResponseProfile.

Read more about Optional Outputs.


The operation scans the image using inScanMap previously generated from a scan path and finds a set of inRidgeCount image ridges perpendicular to the path. If no subset (of inRidgeCount elements) of detected ridges meets the requirements of inRidgeScanParams.minMagnitude, inMinDistance, inRidgeScanParams.ridgePolarity then the outputs are set to NIL.

Note that in case of a scan path which is closed, the parameters controlling the distances between consecutive found objects do not control the distance between the first and the last of the found objects (counting from the beginning of the scan path).


  • Set inRidgeCount to the number of ridges that are to be found (the N number).
  • Define inEdgeScanParams.RidgePolarity to detect a particular ridge type, and only that type.
  • If the expected number of ridges cannot be found, try decreasing inRidgeScanParams.MinMagnitude. Verify this with the values on the outResponseProfile output.
  • If consecutive ridges are very close to each other, change inEdgeScanParams.ProfileInterpolation to Quadratic3.
  • Adjust inMinDistance (in pixels) to filter out false ridges that appear in proximity to other ridges.


ScanMultipleRidges locates the ridges using a scan map representing the scan path above.


Read more about Local Coordinate Systems in Machine Vision Guide: Local Coordinate Systems.

This filter is a part of the 1D Edge Detection toolset. For a comprehensive introduction to this technique please refer to 1D Edge Detection and 1D Edge Detection - Subpixel Precision chapters of our Machine Vision Guide.

See Also

  • CreateScanMap – Precomputes a data object that is required for fast 1D edge detection.
  • ScanSingleRidge – Locates the strongest dark or bright pixel peak along a given path.
  • ScanExactlyNRidges – Locates a specified number of the strongest dark or bright pixel peak along a given path.