【发布时间】: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;
}
这里dx、dy、magnitude分别是图像的x轴导数、y轴导数和幅值。
我所知道的是我找到了整个图像的结构化张量。但我的问题是我需要为图像中的每个像素计算结构化张量。如何做到这一点?
【问题讨论】:
标签: c++ image-processing tensorflow computer-vision