【问题标题】:Implementing Structured Tensor实现结构化张量
【发布时间】:2018-02-23 14:51:32
【问题描述】:

我正在尝试实现一篇名为Structured Tensor Based Image Interpolation 的论文。在论文中,它的作用是使用结构张量根据结构化张量的特征值将图像中的每个像素分为三个不同的类别(均匀、角和边缘)。

为了实现这一点,我编写了以下代码:

void tensorComputation(Mat dx, Mat dy, Mat magnitude)
{

    Mat dx2, dy2, dxy; 
    GaussianBlur(magnitude, magnitude, Size(3, 3), 0, 0, BORDER_DEFAULT); 
    // Calculate image derivatives 
    multiply(dx, dx, dx2);
    multiply(dy, dy, dy2);
    multiply(dx, dy, dxy);

    Mat t(2, 2, CV_32F); // tensor matrix

    // Insert values to the tensor matrix.
    t.at<float>(0, 0) = sum(dx2)[0];
    t.at<float>(0, 1) = sum(dxy)[0];
    t.at<float>(1, 0) = sum(dxy)[0];
    t.at<float>(1, 1) = sum(dy2)[0];

    // eigen decomposition to get the main gradient direction. 
    Mat eigVal, eigVec;
    eigen(t, eigVal, eigVec);

    // This should compute the angle of the gradient direction based on the first eigenvector. 
    float* eVec1 = eigVec.ptr<float>(0);
    float* eVec2 = eigVec.ptr<float>(1);
    cout << fastAtan2(eVec1[0], eVec1[1]) << endl;
    cout << fastAtan2(eVec2[0], eVec2[1]) << endl;
}

这里dxdymagnitude分别是图像的x轴导数、y轴导数和幅值。

我所知道的是我找到了整个图像的结构化张量。但我的问题是我需要为图像中的每个像素计算结构化张量。如何做到这一点?

【问题讨论】:

    标签: c++ image-processing tensorflow computer-vision


    【解决方案1】:

    在您的代码中,您模糊了magnitude,但随后不要使用它。你根本不需要这个量级。

    您正确构建了结构张量,但您对整个图像进行了平均。您要做的是应用 local 平均。对于每个像素,结构张量是矩阵在邻域像素上的平均值。您可以通过对张量的每个分量应用高斯模糊来计算此值:dx2dy2dxy

    高斯的 sigma 越大,平均得到的邻域越大。你会得到更多的正则化(对噪声不太敏感),但分辨率也会更低(对小的变化和短边不太敏感)。玩弄这个参数,直到你得到你需要的东西。 2 到 5 之间的 Sigma 很常见。

    接下来,您需要计算每个像素的特征分解。我不知道 OpenCV 是否让这变得容易。我建议您改用 DIPlib 3。它具有计算和使用结构张量的正确基础设施。 See here how easy it can be.

    【讨论】:

      猜你喜欢
      • 2017-08-10
      • 2022-01-10
      • 2020-03-15
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 2020-12-30
      • 2019-03-01
      • 1970-01-01
      相关资源
      最近更新 更多