Пример #1
0
	void Compute(ImageF& image) {
		const int nx = image.GetWidth();
		const int ny = image.GetHeight();
		const int len = *gvRoiSize;

		// Compute gradients
		gradients.Compute(image);
		MatF& magsqr = gradients.magnitude_sqr;
		magsqr /= magsqr.MaxValue();

		// Create the histogram
		votes.Resize(ny, nx, *gvThetaBins);


		// Compute the (theta,rho,phi) 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);
				}
			}
		}

int main(int argc, char **argv) {
	InitVars(argc, argv, "edgels.cfg");

	ImageF image;
	ImageRGB<byte> imagergb;
	ReadImage(argv[1], imagergb);
	ImageCopy(imagergb, image);
	ResetAlpha(imagergb);
	const int nx = image.GetWidth();
	const int ny = image.GetHeight();

	Edgels edgels(image);
	DREPORT(edgels.edgels.size());

	ImageRGB<byte> canvas;
	ImageCopy(imagergb, canvas);
	BrightColors colors;
	BOOST_FOREACH(const Edgel& e, edgels.edgels) {
		e.Draw(canvas, colors.Next());
	}
	WriteImage("out/all_edgels.png", canvas);

	return 0;
}