清晰化
This commit is contained in:
1 parent
6b67c75c7e
commit
272d3900d0
1 file changed
+52
-4
@@ -828,6 +828,50 @@ public:
|
||||
Pixel8U colEmpty,
|
||||
Mesh::Image8U3Arr& outTextures);
|
||||
|
||||
inline float ComputeLocalVariance(const cv::Mat& image, int patchW, int patchH) {
|
||||
cv::Mat gray;
|
||||
if (image.channels() == 3) {
|
||||
cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
|
||||
} else {
|
||||
gray = image.clone();
|
||||
}
|
||||
|
||||
// 1. 局部方差
|
||||
cv::Mat mean, sqrMean;
|
||||
cv::boxFilter(gray, mean, CV_32F, cv::Size(5, 5));
|
||||
cv::boxFilter(gray.mul(gray), sqrMean, CV_32F, cv::Size(5, 5));
|
||||
cv::Mat variance = sqrMean - mean.mul(mean);
|
||||
float varScore = cv::mean(variance)[0] / 0.08f;
|
||||
|
||||
// 2. 梯度幅值
|
||||
cv::Mat gradX, gradY;
|
||||
cv::Sobel(gray, gradX, CV_32F, 1, 0, 3);
|
||||
cv::Sobel(gray, gradY, CV_32F, 0, 1, 3);
|
||||
cv::Mat magnitude;
|
||||
cv::magnitude(gradX, gradY, magnitude);
|
||||
float gradScore = cv::mean(magnitude)[0] * 3.0f;
|
||||
|
||||
// 3. 直方图熵(可选,衡量纹理丰富度)
|
||||
int histSize = 256;
|
||||
float range[] = {0, 256};
|
||||
const float* histRange = {range};
|
||||
cv::Mat hist;
|
||||
cv::calcHist(&gray, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange);
|
||||
hist /= gray.total();
|
||||
|
||||
float entropy = 0;
|
||||
for (int i = 0; i < histSize; i++) {
|
||||
float p = hist.at<float>(i);
|
||||
if (p > 0) entropy -= p * log2f(p);
|
||||
}
|
||||
float entropyScore = entropy / 8.0f; // 8 bits 的最大熵
|
||||
|
||||
// 综合评分(可调整权重)
|
||||
float complexity = 0.4f * varScore + 0.4f * gradScore + 0.2f * entropyScore;
|
||||
|
||||
return std::min(complexity, 1.0f);
|
||||
}
|
||||
|
||||
inline bool ComputeBarycentric(float u, float v,
|
||||
const TexCoord& uv0, const TexCoord& uv1, const TexCoord& uv2,
|
||||
float& b0, float& b1, float& b2) {
|
||||
@@ -16664,8 +16708,8 @@ bool MeshTexture::RasterizeVirtualFaces(
|
||||
mainPatch.convertTo(mainFloat, CV_32FC3, 1.0f / 255.0f);
|
||||
|
||||
cv::Mat mainLowFreq;
|
||||
cv::GaussianBlur(mainFloat, mainLowFreq, cv::Size(31, 31), 10.0);
|
||||
cv::Mat highFreqAccum = (mainFloat - mainLowFreq) * 0.6f;
|
||||
cv::GaussianBlur(mainFloat, mainLowFreq, cv::Size(5, 5), 1.5);
|
||||
cv::Mat highFreqAccum = (mainFloat - mainLowFreq) * 0.9f;
|
||||
float highFreqTotalWeight = 0.6f;
|
||||
|
||||
if (hasLowFreqViews) {
|
||||
@@ -16784,7 +16828,10 @@ if (hasLowFreqViews && (!vertexVisible[0] || !vertexVisible[1] || !vertexVisible
|
||||
}
|
||||
}
|
||||
|
||||
cv::Mat finalPatch = filledLowFreq * 0.7f + mainFloat * 0.3f;
|
||||
// 使用自适应权重,根据纹理复杂度决定
|
||||
float textureComplexity = ComputeLocalVariance(mainFloat, patchW, patchH);
|
||||
float lowFreqWeight = 0.3f + 0.4f * (1.0f - textureComplexity);
|
||||
cv::Mat finalPatch = filledLowFreq * lowFreqWeight + mainFloat * (1.0f - lowFreqWeight);
|
||||
|
||||
// 钳制到 [0, 1]
|
||||
cv::Mat clampedPatch;
|
||||
@@ -16816,7 +16863,8 @@ if (hasLowFreqViews && (!vertexVisible[0] || !vertexVisible[1] || !vertexVisible
|
||||
|
||||
if (minDist < pad) {
|
||||
weight = minDist / (float)pad;
|
||||
weight = weight * weight;
|
||||
// 使用线性衰减而非平方衰减
|
||||
weight = std::min(minDist / (float)pad, 1.0f); // 原 weight * weight
|
||||
}
|
||||
|
||||
if (currentScore > m_texelScores[idx].score) {
|
||||
|
||||
Reference in new issue
Block a user