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); } } } }