update foe to contact for easy understanding
This commit is contained in:
+1
-28
@@ -41,6 +41,7 @@ def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample
|
||||
# 降噪:在计算散度之后对散度图进行平滑
|
||||
divergence = cv2.GaussianBlur(divergence, (0, 0), denoise_sigma)
|
||||
|
||||
divergence = np.where(divergence>0.02, divergence, 0)
|
||||
# 创建掩码
|
||||
valid_mask = magnitude > min_magnitude
|
||||
expansion_mask = (valid_mask & (divergence > expansion_threshold))
|
||||
@@ -130,31 +131,3 @@ def compute_multiple_foe(flow_field, min_magnitude=1.0, expansion_threshold=0.00
|
||||
result['expansion_regions'].append(contour)
|
||||
|
||||
return result
|
||||
|
||||
def smooth_magnitude(mag, method='moving_average', window_size=5, downsample_factor=4):
|
||||
"""
|
||||
平滑幅度图以减少梯度计算时的伪影。
|
||||
|
||||
Args:
|
||||
mag: 幅度图,形状为 (H, W) 的 numpy 数组
|
||||
method: 平滑方法,'moving_average' 或 'windowed_interpolation'
|
||||
window_size: 移动平均的窗口大小(默认5)
|
||||
downsample_factor: 窗口插值的下采样因子(默认4)
|
||||
|
||||
Returns:
|
||||
np.ndarray: 平滑后的幅度图
|
||||
"""
|
||||
if method == 'moving_average':
|
||||
# 使用移动平均滤波器(box filter)
|
||||
kernel = np.ones((window_size, window_size), dtype=np.float32) / (window_size * window_size)
|
||||
mag_smooth = cv2.filter2D(mag, -1, kernel)
|
||||
elif method == 'windowed_interpolation':
|
||||
# 使用窗口插值:下采样然后插值回原尺寸
|
||||
h, w = mag.shape
|
||||
mag_downsampled = mag[::downsample_factor, ::downsample_factor]
|
||||
mag_smooth = cv2.resize(mag_downsampled, (w, h), interpolation=cv2.INTER_CUBIC)
|
||||
else:
|
||||
# 默认使用高斯滤波
|
||||
mag_smooth = gaussian_filter(mag, sigma=1.5)
|
||||
|
||||
return mag_smooth
|
||||
Reference in New Issue
Block a user