优化pair的点
This commit is contained in:
parent
567765b702
commit
dbccb48411
@ -480,62 +480,46 @@ bool HasConsistentAdjacentPair(
|
|||||||
int curRangeEnd = 0;
|
int curRangeEnd = 0;
|
||||||
GetPairRangeOnLine(pair, useColRange, curRangeStart, curRangeEnd);
|
GetPairRangeOnLine(pair, useColRange, curRangeStart, curRangeEnd);
|
||||||
|
|
||||||
const float curCenter = 0.5f * static_cast<float>(curRangeStart + curRangeEnd);
|
|
||||||
const float curIndexSpan = static_cast<float>(curRangeEnd - curRangeStart);
|
|
||||||
const float curSpanXY = ComputePairSpanXY(pair);
|
const float curSpanXY = ComputePairSpanXY(pair);
|
||||||
|
|
||||||
bool sawComparableNeighbor = false;
|
// 搜索窗口 ±3 行/列,覆盖圆形孔洞边缘处可能跳行/列出现 pair 的情况
|
||||||
bool hasConsistentNeighbor = false;
|
const int kWindow = 3;
|
||||||
|
// 范围重叠容差(索引单位)
|
||||||
|
const int kOverlapTolerance = 2;
|
||||||
|
|
||||||
for (int lineOffset = -1; lineOffset <= 1; lineOffset += 2) {
|
for (int lineOffset = -kWindow; lineOffset <= kWindow; lineOffset++) {
|
||||||
|
if (lineOffset == 0) continue;
|
||||||
int neighborLine = lineIndex + lineOffset;
|
int neighborLine = lineIndex + lineOffset;
|
||||||
if (neighborLine < 0 || neighborLine >= static_cast<int>(allLinePairs.size())) {
|
if (neighborLine < 0 || neighborLine >= static_cast<int>(allLinePairs.size())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& neighborPair : allLinePairs[neighborLine]) {
|
for (const auto& neighborPair : allLinePairs[neighborLine]) {
|
||||||
int neighborRangeStart = 0;
|
int nRangeStart = 0;
|
||||||
int neighborRangeEnd = 0;
|
int nRangeEnd = 0;
|
||||||
GetPairRangeOnLine(neighborPair, useColRange, neighborRangeStart, neighborRangeEnd);
|
GetPairRangeOnLine(neighborPair, useColRange, nRangeStart, nRangeEnd);
|
||||||
|
|
||||||
const float neighborCenter = 0.5f * static_cast<float>(neighborRangeStart + neighborRangeEnd);
|
// 范围重叠检查(带容差):两个 pair 的列/行范围必须有交集
|
||||||
const float neighborIndexSpan = static_cast<float>(neighborRangeEnd - neighborRangeStart);
|
if (curRangeEnd + kOverlapTolerance < nRangeStart ||
|
||||||
const float overlap = static_cast<float>(
|
nRangeEnd + kOverlapTolerance < curRangeStart) {
|
||||||
std::min(curRangeEnd, neighborRangeEnd) - std::max(curRangeStart, neighborRangeStart)
|
|
||||||
);
|
|
||||||
const float centerDiff = std::abs(curCenter - neighborCenter);
|
|
||||||
const float maxIndexSpan = std::max(curIndexSpan, neighborIndexSpan);
|
|
||||||
|
|
||||||
const bool hasPositionMatch =
|
|
||||||
(overlap >= -1.0f) ||
|
|
||||||
(centerDiff <= std::max(2.0f, maxIndexSpan * 0.5f + 1.0f));
|
|
||||||
if (!hasPositionMatch) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sawComparableNeighbor = true;
|
// 物理跨度一致性:圆形孔洞相邻行/列的 pair 跨度渐变,
|
||||||
|
// 差异不应超过较大者的 50%(兼顾孔洞边缘处的快速变化)
|
||||||
const float neighborSpanXY = ComputePairSpanXY(neighborPair);
|
const float neighborSpanXY = ComputePairSpanXY(neighborPair);
|
||||||
const float maxSpanXY = std::max(curSpanXY, neighborSpanXY);
|
const float maxSpanXY = std::max(curSpanXY, neighborSpanXY);
|
||||||
const float spanDiff = std::abs(curSpanXY - neighborSpanXY);
|
const float spanDiff = std::abs(curSpanXY - neighborSpanXY);
|
||||||
const float allowedSpanDiff = std::max(params.minFeatureSpan * 2.0f, maxSpanXY * 0.45f);
|
const float allowedSpanDiff = std::max(params.minFeatureSpan * 2.0f, maxSpanXY * 0.5f);
|
||||||
|
|
||||||
if (spanDiff <= allowedSpanDiff) {
|
if (spanDiff <= allowedSpanDiff) {
|
||||||
hasConsistentNeighbor = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasConsistentNeighbor) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sawComparableNeighbor) {
|
// 在 ±kWindow 范围内找不到范围重叠且跨度一致的邻居 → 孤立噪声,丢弃
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return hasConsistentNeighbor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterPairsByAdjacentConsistency(
|
void FilterPairsByAdjacentConsistency(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user