void Compute(const ImageRGB<byte>& imagergb, const ImageHSV<byte>& imagehsv, const MatI& seg, int num_segments) { const int& w = imagergb.GetWidth(); const int& h = imagergb.GetHeight(); // Compute pixel features pixel_ftrs.Compute(imagergb, imagehsv); // Build histograms over labels for each segment hists.Resize(num_segments, pixel_ftrs.label_map.MaxValue()+1); hists.Fill(0); for (int r = 0; r < h; r++) { const int* labelrow = pixel_ftrs.label_map[r]; const int* segrow = seg[r]; for (int c = 0; c < w; c++) { hists[ segrow[c] ][ labelrow[c] ]++; } } // Normalize the histograms features.resize(num_segments); for (int i = 0; i < num_segments; i++) { features[i] = hists.GetRow(i); features[i] /= features[i].Sum(); } }
void Compute(const ROI& roi, const MatI& mask, const MatF& magsqr, const MatF& orient) { const float cx = roi.CenterX(); const float cy = roi.CenterY(); diaglen = sqrtf(roi.Width()*roi.Width() + roi.Height()*roi.Height()); edgels.clear(); hist.Resize(*gvThetaBins, *gvRhoBins); hist.Fill(0); // Compute the (theta,rho) histogram for (int y = roi.Top(); y < roi.Bottom(); y++) { const float* orientrow = orient[y]; const float* magrow = magsqr[y]; for (int x = roi.Left(); x < roi.Right(); x++) { if (mask[y-roi.Top()][x-roi.Left()]) { const float theta = OpenUpAngle(orientrow[x]); const float rho = (x-cx) * cos(theta) + (y-cy) * sin(theta); const int theta_bin = ThetaToBin(theta); const int rho_bin = RhoToBin(rho); const float mag = sqrtf(magrow[x]); hist[theta_bin][rho_bin] += mag; } } } // Find edgels int nn = 0; for (int y = 0; y < hist.Rows(); y++) { for (int x = 0; x < hist.Cols(); x++) { if (hist[y][x] >= *gvThresh) { const float theta = BinToTheta(y); const float rho = BinToRho(x); const float costh = cos(theta); const float sinth = sin(theta); const Vec3F line(costh, sinth, -cx*costh - cy*sinth - rho); Edgel cur(theta, rho, hist[y][x], line); ClipLineToROI(cur.line, roi, cur.start, cur.end); edgels.push_back(cur); } } } }
pcl2::TypedMat<int> pcl2::findFixedRadiusNeighbors (Cloud & cloud, const MatF & query, float r) { // Search in the xyx channel MatF xyz = cloud["xyz"]; // Look for a pre-computed spatial search index SpatialIndex<float>::Ptr spatial_index = xyz.getSpatialIndex (); if (!spatial_index) { // If no spatial index is present, create one /// \todo: Replace this with buildDefaultSpatialIndex, getSpatialIndex spatial_index.reset (new search::KDTree<float> ()); xyz.buildSpatialIndex (spatial_index); } // Use the search index to perform the radius search and return the neigbhor indices return (spatial_index->findFixedRadiusNeighbors (query, r)); }
pcl2::Neighborhood pcl2::computeFixedRadiusNeighborhood (Cloud & cloud, const MatF & query, float r) { // Convert point cloud MatF xyz = cloud["xyz"]; assert (xyz.rows () >= 1); assert (xyz.cols () == 3); pcl::PointCloud<pcl::PointXYZ>::Ptr input (new pcl::PointCloud<pcl::PointXYZ>); input->width = cloud.size (); input->height = 1; input->is_dense = false; input->points.resize (cloud.size ()); for (size_t i = 0; i < xyz.rows (); ++i) { input->points[i].x = xyz (i, 0); input->points[i].y = xyz (i, 1); input->points[i].z = xyz (i, 2); } // Convert query point assert (query.rows () == 1); assert (query.cols () == 3); pcl::PointXYZ q; q.x = query (0, 0); q.y = query (0, 1); q.z = query (0, 2); // Perform neighbor search pcl::KdTreeFLANN<pcl::PointXYZ> tree; tree.setInputCloud (input); std::vector<int> idx_vec; std::vector<float> dist_vec; size_t k = (size_t) tree.radiusSearch (q, r, idx_vec, dist_vec); assert (k == idx_vec.size ()); // Convert output EigenMat<int> neighbor_indices (k, 1); EigenMat<float> squared_distances (k, 1); for (size_t i = 0; i < k; ++i) { neighbor_indices (i, 0) = idx_vec[i]; squared_distances (i, 0) = dist_vec[i]; } //Cloud neighborhood = cloud (neighbor_indices); Neighborhood neighborhood (cloud, neighbor_indices); neighborhood.insert ("dist", squared_distances); return (neighborhood); }
pcl2::TypedMat<int> pcl2::findKNearestNeighbors (const Cloud & cloud, const MatF & query, size_t k) { // Convert point cloud MatF xyz = cloud["xyz"]; assert (xyz.rows () >= 1); assert (xyz.cols () == 3); pcl::PointCloud<pcl::PointXYZ>::Ptr input (new pcl::PointCloud<pcl::PointXYZ>); input->width = cloud.size (); input->height = 1; input->is_dense = false; input->points.resize (cloud.size ()); for (size_t i = 0; i < xyz.rows (); ++i) { input->points[i].x = xyz (i, 0); input->points[i].y = xyz (i, 1); input->points[i].z = xyz (i, 2); } // Convert query point assert (query.rows () == 1); assert (query.cols () == 3); pcl::PointXYZ q; q.x = query (0, 0); q.y = query (0, 1); q.z = query (0, 2); // Perform neighbor search pcl::KdTreeFLANN<pcl::PointXYZ> tree; tree.setInputCloud (input); std::vector<int> indices (k); std::vector<float> dists (k); k = (size_t) tree.nearestKSearch (q, k, indices, dists); assert (k == indices.size ()); // Convert output EigenMat<int> output (k, 1); for (size_t i = 0; i < indices.size (); ++i) output (i, 0) = indices[i]; return (output); }
IGL_INLINE void igl::arap_linear_block_spokes( const MatV & V, const MatF & F, const int d, Eigen::SparseMatrix<Scalar> & Kd) { using namespace std; using namespace Eigen; // simplex size (3: triangles, 4: tetrahedra) int simplex_size = F.cols(); // Number of elements int m = F.rows(); // Temporary output Matrix<int,Dynamic,2> edges; Kd.resize(V.rows(), V.rows()); vector<Triplet<Scalar> > Kd_IJV; if(simplex_size == 3) { // triangles Kd.reserve(7*V.rows()); Kd_IJV.reserve(7*V.rows()); edges.resize(3,2); edges << 1,2, 2,0, 0,1; }else if(simplex_size == 4) { // tets Kd.reserve(17*V.rows()); Kd_IJV.reserve(17*V.rows()); edges.resize(6,2); edges << 1,2, 2,0, 0,1, 3,0, 3,1, 3,2; } // gather cotangent weights Matrix<Scalar,Dynamic,Dynamic> C; cotmatrix_entries(V,F,C); // should have weights for each edge assert(C.cols() == edges.rows()); // loop over elements for(int i = 0;i<m;i++) { // loop over edges of element for(int e = 0;e<edges.rows();e++) { int source = F(i,edges(e,0)); int dest = F(i,edges(e,1)); double v = 0.5*C(i,e)*(V(source,d)-V(dest,d)); Kd_IJV.push_back(Triplet<Scalar>(source,dest,v)); Kd_IJV.push_back(Triplet<Scalar>(dest,source,-v)); Kd_IJV.push_back(Triplet<Scalar>(source,source,v)); Kd_IJV.push_back(Triplet<Scalar>(dest,dest,-v)); } } Kd.setFromTriplets(Kd_IJV.begin(),Kd_IJV.end()); Kd.makeCompressed(); }
IGL_INLINE void igl::faces_first( const MatV & V, const MatF & F, MatV & RV, MatF & RF, VecI & IM) { assert(&V != &RV); assert(&F != &RF); using namespace std; using namespace Eigen; vector<bool> in_face(V.rows()); for(int i = 0; i<F.rows(); i++) { for(int j = 0; j<F.cols(); j++) { in_face[F(i,j)] = true; } } // count number of vertices not in faces int num_in_F = 0; for(int i = 0;i<V.rows();i++) { num_in_F += (in_face[i]?1:0); } // list of unique vertices that occur in F VectorXi U(num_in_F); // list of unique vertices that do not occur in F VectorXi NU(V.rows()-num_in_F); int Ui = 0; int NUi = 0; // loop over vertices for(int i = 0;i<V.rows();i++) { if(in_face[i]) { U(Ui) = i; Ui++; }else { NU(NUi) = i; NUi++; } } IM.resize(V.rows()); // reindex vertices that occur in faces to be first for(int i = 0;i<U.size();i++) { IM(U(i)) = i; } // reindex vertices that do not occur in faces to come after those that do for(int i = 0;i<NU.size();i++) { IM(NU(i)) = i+U.size(); } RF.resize(F.rows(),F.cols()); // Reindex faces for(int i = 0; i<F.rows(); i++) { for(int j = 0; j<F.cols(); j++) { RF(i,j) = IM(F(i,j)); } } RV.resize(V.rows(),V.cols()); // Reorder vertices for(int i = 0;i<V.rows();i++) { RV.row(IM(i)) = V.row(i); } }