System designExplainer

Measuring image pattern strength with spatial regularity

Measure image pattern strength using autocorrelation and Fourier energy, with sampling calculations and tests that separate regular texture from noise.

LumaSpec Vision11 min read Share on LinkedIn

On this page 10 sections
  1. 01Define the repetition you need to measure
  2. 02Prepare a consistent measurement region
  3. 03Measure repetition with normalized autocorrelation
  4. 04Confirm periodicity with Fourier energy
  5. 05Work through a sampled grating example
  6. 06Choose acquisition hardware around the measurement
  7. 07Validate scores against representative inspection images
  8. 08Recognize when a periodicity score is the wrong answer
  9. 09Check the setup before ordering or deployment
  10. 10Questions

A regular stripe pattern, an irregular set of bars and random noise can share the same average brightness. They can also have similar contrast, making intensity statistics poor measures of their spatial order. This is a common inspection problem when checking printed textures, repeating grooves or material surfaces. Start by defining which spacing and direction should repeat, then measure that repetition independently of brightness. The method below combines autocorrelation with spectral energy and explains how to validate both against production images.

Define the repetition you need to measure

For this task, image pattern strength means repeatable spatial structure at a specified spacing and direction. It does not mean image quality, contrast, sharpness or the number of separate dark regions.

A square-wave grating repeats predictably. Irregular bars may share its direction but not its spacing. Random noise contains local variations without a stable repeating interval. These differences suggest measuring several attributes rather than forcing everything into a universal score.

Measurement What it answers Why it cannot stand alone
Mean intensity How bright is the region? Different textures can have identical means
Intensity standard deviation How much tonal variation exists? High-contrast noise can exceed a useful pattern
Blob count How many segmented regions exist? Thresholds and noise can create extra regions
Directionality Does the texture favor an orientation? Irregular bars can be strongly directional
Autocorrelation Does structure repeat after a displacement? A limited search can miss the true period
Harmonic energy concentration Is energy concentrated around expected repeating frequencies? Window size and selected bands affect the result

Keep contrast as an eligibility check, not as the definition of regularity. A nearly uniform image should produce an insufficient-signal result rather than a confident pattern score.

If your actual task is reading encoded bars, use the separate guidance on barcode preprocessing for rotation, blur and glare. Irregular spacing can be intentional information rather than a defect.

Prepare a consistent measurement region

Choose a region of interest containing the texture without borders, labels or unrelated edges. Keep its physical coverage and pixel dimensions consistent across comparisons.

For approximately vertical bars, average image values down the rows to obtain a horizontal intensity profile. This reduces uncorrelated pixel noise while retaining variation across the bars. It also discards vertical detail, so it is unsuitable when defects along individual bars matter.

Correct orientation before extracting the profile. Slanted bars can cancel during row averaging because their edges occur at different horizontal positions. For textures with unknown orientation, use a two-dimensional analysis or estimate orientation before reducing the image.

Apply these preparation rules consistently:

  • Use the same grayscale conversion and intensity scaling.
  • Exclude saturated pixels and confirm that useful contrast remains.
  • Subtract the profile mean before spectral analysis.
  • Remove a gradual background trend only if it is unrelated to the inspection requirement.
  • Preserve the unprocessed image for diagnosis.

Avoid adaptive thresholding as the default input. It can create or remove structure before you measure it. The distinction between analysis data and display output is covered in binary image previews for defect inspection.

Measure repetition with normalized autocorrelation

Autocorrelation compares a signal with a displaced copy of itself. A regularly repeating profile resembles itself again when the displacement equals its period.

For each positive displacement, use only the overlapping samples. Calculate a normalized correlation coefficient between those two overlapping vectors:

s[x] = mean image intensity down the selected rows a_d = s[0 : W-d] b_d = s[d : W] A(d) = sum((a_d - mean(a_d)) × (b_d - mean(b_d))) / sqrt(sum((a_d - mean(a_d))²) × sum((b_d - mean(b_d))²))

Here, W is the profile width in pixels and d is displacement in pixels. Slice endpoints are excluded. If either vector has negligible variance, mark that result invalid instead of dividing by a nearly zero denominator.

The coefficient ranges from -1 to 1. A strong positive peak at the expected period supports repetition. A negative value means that bright and dark regions tend to exchange positions at that displacement.

Do not search every displacement and report the largest value. Adjacent pixels often correlate because of optics, interpolation and broad bars. Large displacements also leave fewer overlapping samples, making accidental peaks more influential.

Instead, define a permitted period range from the inspection requirement. As a practical starting point, restrict displacement to no more than one quarter of the profile width. Include enough texture to observe at least eight expected periods when possible. These are setup rules to validate, not universal acceptance limits.

Check for a second peak near twice the estimated period. Agreement across several repetitions is more persuasive than one isolated peak. Preserve peak location and peak height separately: a strong pattern at the wrong spacing may still be a failed part.

Confirm periodicity with Fourier energy

A Fourier transform describes how much variation occurs at each spatial frequency. A repeating grating concentrates energy near its fundamental frequency and, depending on its shape, its harmonics.

A square-wave pattern is not a single-frequency signal. An ideal, balanced square wave contains odd harmonics in addition to the fundamental. Measuring only the tallest spectral bin would therefore understate its ordered structure.

For a horizontal profile, use this sequence:

  1. Subtract its mean and apply any previously specified detrending.
  2. Apply a fixed window, such as a Hann window, to reduce boundary leakage.
  3. Calculate a consistently scaled, single-sided power spectrum.
  4. Sum power within predefined bands around the expected fundamental and permitted harmonics.
  5. Divide that sum by all non-DC spectral power.
f0 = 1 / expected period C = sum(P[k] for k in the accepted frequency bands) / sum(P[k] for all retained non-DC frequencies)

C lies between 0 and 1 when the denominator is positive and the numerator contains a subset of its bins. Count each bin only once when bands overlap. Use the same window, bin weighting and frequency exclusions for every image.

Define accepted bands before evaluating production parts. Allow for spacing tolerance and window broadening, but do not include so many harmonics that the bands cover most of the spectrum. Noise would then score highly simply because little energy remains outside them.

Irregular bars can produce directional spectral energy without narrow periodic peaks. Random noise tends to spread energy broadly, although any finite image can contain accidental concentrations. Compare scores with representative noise images rather than assuming noise always scores zero.

Work through a sampled grating example

Suppose an inspection region spans 64 mm across 256 pixels. The desired texture repeats every 4 mm, with equal bright and dark widths.

Object sampling = 64 mm / 256 pixels = 0.25 mm/pixel Pixels per period = 4 mm / 0.25 mm/pixel = 16 pixels Pixels per bright or dark bar = 16 / 2 = 8 pixels Periods in the region = 256 / 16 = 16

The narrowest bar is therefore 2 mm wide. If the design target is eight pixels across that bar, the minimum horizontal pixel count for this field is:

Required horizontal pixels = 64 mm × 8 pixels / 2 mm = 256 pixels

Use the camera finder to compare available imaging formats after establishing the required sampling. The resolution calculator can help translate field coverage and feature size into a pixel requirement.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

For an ideal sampled profile containing eight bright samples followed by eight dark samples, correlation at a displacement of 16 pixels is 1. At eight pixels, it is -1. Real images deviate because of noise, edge shape, spacing variation and illumination.

The fundamental spatial frequency is 1 / 16 = 0.0625 cycles per pixel. A profile width of 256 pixels gives a Fourier-bin spacing of 1 / 256 = 0.00390625 cycles per pixel. The fundamental therefore falls at bin 16; its third and fifth harmonics fall at bins 48 and 80.

Suppose an analyzed profile has 84 normalized energy units inside the accepted bands and 120 across all retained bins. Its concentration is 84 / 120 = 0.70. Another profile with 30 accepted units and the same total scores 0.25. These illustrative values explain the arithmetic; they are not proposed acceptance thresholds.

Choose acquisition hardware around the measurement

Start with area scan cameras when your application needs accessible image data and processing outside the camera. Select resolution from field coverage and feature sampling, then consider exposure, shutter behavior, interface and image-transfer requirements.

The LS-CMR-0053 is a GigE area scan camera with a rolling shutter. Confirm that its acquisition behavior fits the motion conditions and required image quality.

Area scan cameras12 MP GigE area scan camera, IMX226, 1/1.7" rolling shutter, 9 fps (LS-CMR-0053)LS-CMR-0053
Sensor format
1/1.7"
Interface
GigE
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

The LS-CMR-0166 is a USB3 area scan camera with a rolling shutter. Treat interface selection as an integration decision rather than evidence that a texture algorithm will run on the device.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

Neither transport interface determines the validity of autocorrelation or spectral analysis. Software access to the required pixels and stable acquisition settings matter more directly.

For smart cameras, verify that the documented processing tools support the required operations or allow suitable image export. Do not assume that every device provides a Fourier transform, custom normalized correlation or access to intermediate arrays.

If processing runs on vision controllers, confirm image-interface compatibility, software licensing, recipe storage and processing latency. Size the computing workload from measured execution times with the intended image dimensions and acquisition rate.

Freeze exposure and gain during score comparison unless changing illumination is explicitly part of the validation. Follow the guidance on automatic iris, exposure and gain control when determining which settings should remain automatic.

Validate scores against representative inspection images

Build a labeled dataset before choosing a threshold. Include acceptable patterns, wrong-spacing patterns, irregular bars, blank surfaces, random texture and realistic acquisition faults.

Separate production examples from software-generated test images. Synthetic gratings are useful for checking arithmetic and expected peak positions, but they do not reproduce every reflection, surface variation or focus error.

Record at least these outputs for each image:

  • Input contrast and the valid-signal decision.
  • Estimated orientation, if orientation compensation is used.
  • Best period within the permitted search range.
  • Correlation at that period and near its next repetition.
  • Spectral concentration using the fixed bands.
  • Exposure, gain and region dimensions.

Vary acquisition conditions deliberately. For example, test nominal exposure alongside settings 20% lower and higher, while avoiding clipping. Repeat at the allowed focus and orientation limits. A large score change can reveal an acquisition dependency rather than a material defect.

Split data by physical sample or production batch, not merely by neighboring frames. Otherwise, nearly identical images can appear in both tuning and validation sets and exaggerate performance.

Choose thresholds from the observed false-accept and false-reject consequences. If no false accepts appear among 100 defective examples, report that observation without claiming a proven zero failure rate.

For motion inspection, also check whether acquisition settings alter texture geometry. The guidance on hardware-trigger frame rate with external pulses helps separate requested acquisition timing from actual delivered frames.

Recognize when a periodicity score is the wrong answer

High regularity is not automatically good quality. A missing bar can leave most of a large region periodic, producing a strong aggregate score despite a local defect.

Use smaller overlapping regions when defect location matters. For example, a 256-pixel window advanced by 64 pixels gives 75% overlap. Validate the smaller region again because fewer visible repetitions increase score variability.

A spacing gradient, curved texture or mixed orientation may distribute spectral energy even when the material is acceptable. Consider local orientation and local period estimates instead of one global concentration value.

Conversely, illumination banding, repeating sensor artifacts or processing resampling can create strong periodicity unrelated to the part. Capture a uniform reference surface and inspect the raw image before interpreting unexpected peaks.

The theoretical sampling boundary also requires care. Two samples per sinusoidal period describe a limiting sampling condition, not a reliable inspection target for square-wave bars. Additional samples help preserve edge shape and tolerate focus or alignment changes. Validate the chosen sampling with actual optics rather than relying on pixel count alone.

Check the setup before ordering or deployment

Use this checklist to turn the method into a repeatable inspection recipe:

  • Define the physical period, permitted tolerance and relevant orientation.
  • Specify the smallest feature and required samples across it.
  • Check field coverage, focus and mounting clearance.
  • Confirm raw-image access and supported processing operations.
  • Fix region dimensions, preprocessing and frequency-band definitions.
  • Reject insufficient contrast before calculating normalized scores.
  • Save peak positions as well as correlation and concentration values.
  • Test wrong-spacing patterns, isolated defects and acquisition faults.
  • Verify processing latency with the intended acquisition workload.
  • Version the recipe and retain representative acceptance images.

For hardware selection, start with the camera configuration step. For an existing inspection, send representative images, field dimensions, expected spacing and acceptance requirements through applications support. Those details provide a useful basis for choosing acquisition hardware and deciding whether periodicity is the right measurement.

Questions

Why can images with the same brightness have different pattern strength?

Equal brightness says nothing about where pixels occur. A repeating grating and a random arrangement can have matching intensity distributions but different spatial relationships. Correlation measures similarity after displacement, while spectral analysis identifies how variation is distributed across spatial frequencies.

Should a Fourier score include harmonics?

For a balanced square-wave texture, include the expected fundamental and selected odd harmonics. Keep the accepted bands fixed and account for finite-window leakage. Using only the fundamental can penalize a well-formed square wave, while accepting too many bands can make random texture appear regular.

How many repetitions should the inspection region contain?

Eight visible periods is a useful initial target for a stable region-level measurement, but the final requirement depends on noise, spacing tolerance and defect size. Larger regions improve frequency discrimination while potentially hiding isolated defects. Validate both the region size and any overlapping local windows.

Can a smart camera calculate these measurements?

Only when the device's documented tools provide the necessary calculations or suitable image export. Check access to grayscale data, region controls, correlation operations and spectral processing before selection. Camera resolution and interface alone do not establish support for a particular texture algorithm.

Is there a universal passing score for image pattern strength?

No universal threshold applies across materials and acquisition setups. Establish thresholds using labeled acceptable and defective samples, including realistic focus, illumination and orientation variation. Keep a separate validation set and retain an invalid-signal outcome for images with inadequate contrast or saturation.