You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Halcon中基于FFT功率谱计算图像light drafts周期性的后续处理方案咨询

Halcon中基于FFT功率谱计算图像light drafts周期性的后续处理方案咨询

Hey there! Let's walk through exactly what you need to do next to extract the periodicity from your power spectrum in Halcon. You’ve already nailed the core FFT and power spectrum steps—nice work getting that far!

核心思路梳理

First, let’s recap what your current code does: you’ve removed the vertical background variation with a tall median filter, isolated the horizontal light draft fluctuations, converted to the frequency domain, and calculated the power spectrum. The power spectrum’s peaks correspond to the repeating frequencies in your image, and we just need to map those peaks back to a real-world periodicity (in pixels).

Since you’re dealing with horizontal light drafts (your median filter targets vertical background), we’ll focus on horizontal frequency components in the power spectrum.


Step-by-Step Code & Explanations

1. First, visualize your power spectrum (critical for debugging)

Before diving into calculations, take a look at your power spectrum to confirm where peaks are located:

dev_display(ImageResult)
disp_message(WindowHandle, 'Power Spectrum - look for peaks away from the center', 'window', 12, 12, 'black', 'true')

The center of the power spectrum is the DC component (average brightness), so we’ll ignore that and look for sharp peaks offset from the center.

2. Convert the 2D power spectrum to a 1D projection (easier peak detection)

Since we care about horizontal periodicity, we can collapse the power spectrum into a 1D array by summing each column’s pixel values. This simplifies finding the dominant frequency:

// Create a column-wise projection of the power spectrum
projection_col(ImageResult, ImageProjection)

// Extract the 1D power values from the projection image
get_image_pointer1(ImageProjection, Pointer, Type, WidthProj, HeightProj)
gen_region_line(RegionLine, 0, 0, HeightProj - 1, 0)
get_region_points(RegionLine, Rows, Columns)
get_grayval(ImageProjection, Rows, Columns, PowerValues)

3. Find the dominant peak (ignore the DC component)

The DC component sits at the center of the projection array. We’ll skip a small area around it to avoid picking up the background signal:

// Calculate the position of the DC component (center of the projection)
dc_pos = floor(WidthProj / 2)

// Define a search range that skips the DC area (adjust the 5-pixel offset if needed)
search_start = 0
search_end = dc_pos - 5

// Find the maximum peak in the left half (FFT is symmetric, so left/right peaks are identical)
find_max(PowerValues, search_start, search_end, max_power, peak_pos)

4. Calculate the periodicity from the peak position

Periodicity is the inverse of frequency. Here’s how to map the peak’s position to a pixel-based period:

// Calculate the frequency offset from the DC component
frequency_offset = abs(peak_pos - dc_pos)

// Periodicity = original image width / frequency offset
periodicity = Width / frequency_offset

// Display the result on your original image
dev_display(img)
disp_message(WindowHandle, 'Calculated Periodicity: ' + periodicity + ' pixels', 'window', 12, 12, 'forest green', 'true')

Pro Tips for Better Results

  • Smooth the power spectrum first: If your power spectrum has noisy small peaks, apply a Gaussian filter to clean it up before projection:
    gauss_filter(ImageResult, ImageSmoothed, 3)
    
  • Validate with visual checks: After calculating the period, draw lines on your original image at intervals equal to the periodicity to confirm it matches the light draft spacing:
    for i from 0 to Width by periodicity
        gen_region_line(RegionPeriod, 0, i, Height - 1, i)
        dev_display(RegionPeriod)
    endfor
    
  • Handle multiple peaks: If there are multiple significant peaks, you might need to analyze the top N peaks and pick the one that aligns with your expected light draft pattern.

备注:内容来源于stack exchange,提问作者Vincenzo La Forgia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 07:14:49