void NCut::GetPatchFeature(const MatrixXf &points, MatrixXf *features_in) { MatrixXf &features = *features_in; const int num_points = static_cast<int>(points.rows()); const int dim = _patch_size * _patch_size; features.resize(num_points, dim); for (int i = 0; i < num_points; ++i) { // .1 patch int irow = 0; int jcol = 0; _ff_feature_grid.Pos2d(points.coeffRef(i, 0), points.coeffRef(i, 1), &irow, &jcol); cv::Mat patch; cv::Point2f pt(static_cast<float>(irow), static_cast<float>(jcol)); cv::getRectSubPix(_cv_feature_map, cv::Size(_patch_size, _patch_size), pt, patch); // .2 maybe later i will add other features based on patch // .3 add to features assert(dim == patch.rows * patch.cols); int p = 0; for (int r = 0; r < patch.rows; ++r) { for (int c = 0; c < patch.cols; ++c) { float val = patch.at<float>(r, c); features.coeffRef(i, p++) = static_cast<float>( (std::isnan(val) || std::isinf(val)) ? 1.e-50 : val); // features.coeffRef(i, p++) = patch.at<float>(r, c); } } } }
时间: 2024-04-03 20:36:52 浏览: 49
这段代码是用于计算NCut算法中的图像块的特征向量。给定一个点集points,对于每个点,首先通过_ff_feature_grid将其映射到_feature_map图像上,并取该点为中心的_patch_size * _patch_size大小的矩形区域作为图像块。然后,对于每个图像块,将像素值添加到特征向量中,特征向量的维度为_patch_size * _patch_size。在添加每个像素值时,如果该值为NaN或Inf,则设置为1.e-50。最终,返回一个特征向量矩阵features,其行数为points中点的个数,列数为_patch_size * _patch_size。
相关问题
Prove u⊤Lu/u⊤Du = Ncut(A, B)
To prove u⊤Lu/u⊤Du = Ncut(A, B), we need to show that both sides are equal to the normalized cut objective function.
First, let's consider the left-hand side of the equation:
u⊤Lu/u⊤Du
Recall that the normalized cut objective function is defined as:
Ncut(A, B) = (cut(A, B) / vol(A)) + (cut(A, B) / vol(B))
where cut(A, B) is the sum of the weights of edges between nodes in A and nodes in B, vol(A) is the sum of the weights of edges incident to nodes in A, and vol(B) is the sum of the weights of edges incident to nodes in B.
Note that we can rewrite the numerator of the left-hand side of the equation as:
u⊤Lu = u⊤(D - W)u = u⊤Du - u⊤Wu
where D is the diagonal degree matrix, W is the adjacency matrix, and u is the eigenvector corresponding to the second smallest eigenvalue of the Laplacian matrix L.
Using the definition of vol(A) and vol(B), we can rewrite the denominator of the left-hand side of the equation as:
u⊤Du = u⊤(D_A + D_B)u = u⊤D_Au + u⊤D_Bu
where D_A and D_B are the diagonal degree matrices of the subgraphs induced by nodes in A and nodes in B, respectively.
Substituting these expressions into the left-hand side of the equation, we get:
u⊤Lu/u⊤Du = (u⊤Du - u⊤Wu) / (u⊤D_Au + u⊤D_Bu)
Multiplying both the numerator and denominator by 1/vol(A) + 1/vol(B), we obtain:
(u⊤Du - u⊤Wu) / (u⊤D_Au + u⊤D_Bu) * (1/vol(A) + 1/vol(B)) = (cut(A, B) / vol(A)) + (cut(A, B) / vol(B))
which is precisely the normalized cut objective function.
Therefore, we have shown that u⊤Lu/u⊤Du = Ncut(A, B), as required.
CMake Error at CMakeLists.txt:22 (message): Search for 'catkin' in workspace failed (catkin_find_pkg catkin /home/ncut/test/src): Traceback (most recent call last):
这个错误信息表示在你的工作区中没有找到名为`catkin`的包,而在你的CMakeLists.txt文件中需要使用到这个包。可能是你的工作区中没有安装catkin或者catkin的安装路径不在CMakeLists.txt中指定的路径中。
你可以尝试检查你的工作区中是否已经安装了catkin,并且确保在CMakeLists.txt中正确指定了catkin的路径。如果你没有安装catkin,可以通过以下命令安装:
```
sudo apt-get install ros-<your-ros-version>-catkin
```
其中,`<your-ros-version>`是你正在使用的ROS版本,比如,如果你正在使用ROS Kinetic,那么命令应该是:
```
sudo apt-get install ros-kinetic-catkin
```
安装完成后,重新运行CMake即可。
阅读全文