Ejemplo n.º 1
0
/**
 * Fill in the particle analysis report.
 * For a given image, fill in the particle analysis report structure.
 * @param imageParam the image to use
 * @param particleNumber the particle index in the set of particles for the image
 * @param par the particle analysis report to be filled in
 */
int BinaryImage::ParticleAnalysis(Image* imageParam, int particleNumber, ParticleAnalysisReport* par)
{
	int success = 0;

	success = imaqGetImageSize(imageParam, &par->imageWidth, &par->imageHeight);
	wpi_imaqAssert(success, "Error getting image size");
	
	par->particleIndex = particleNumber;		
	
	success = imaqCountParticles(imageParam, TRUE, NULL);
	wpi_imaqAssert(success, "Error counting particles");
	
	par->center_mass_x = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_CENTER_OF_MASS_X);
	par->center_mass_y = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_CENTER_OF_MASS_Y);
	par->particleArea = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_AREA);	
	par->boundingRect.top = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_BOUNDING_RECT_TOP);
	par->boundingRect.left = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_BOUNDING_RECT_LEFT);
	par->boundingRect.height = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_BOUNDING_RECT_HEIGHT);
	par->boundingRect.width = (int) particleMeasurement(imageParam, particleNumber, IMAQ_MT_BOUNDING_RECT_WIDTH);
	par->particleToImagePercent = particleMeasurement(imageParam, particleNumber, IMAQ_MT_AREA_BY_IMAGE_AREA);
	par->particleQuality = particleMeasurement(imageParam, particleNumber, IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA);

	/* normalized position (-1 to 1) */
	par->center_mass_x_normalized = NormalizeFromRange(par->center_mass_x, par->imageWidth);
	par->center_mass_y_normalized = NormalizeFromRange(par->center_mass_y, par->imageHeight);

	return success;
}
Ejemplo n.º 2
0
/**
 * Get a single particle analysis report.
 * Get one (of possibly many) particle analysis reports for an image.
 * This version could be more efficient when copying many reports.
 * @param particleNumber Which particle analysis report to return.
 * @param par the selected particle analysis report
 */
void BinaryImage::GetParticleAnalysisReport(int particleNumber, ParticleAnalysisReport *par)
{
	int success;
	int numParticles = 0;

	success = imaqGetImageSize(m_imaqImage, &par->imageWidth, &par->imageHeight);
	wpi_setImaqErrorWithContext(success, "Error getting image size");
	if (StatusIsFatal())
		return;

	success = imaqCountParticles(m_imaqImage, 1, &numParticles);
	wpi_setImaqErrorWithContext(success, "Error counting particles");
	if (StatusIsFatal())
		return;

	if (particleNumber >= numParticles)
	{
		wpi_setWPIErrorWithContext(ParameterOutOfRange, "particleNumber");
		return;
	}

	par->particleIndex = particleNumber;
	// Don't bother measuring the rest of the particle if one fails
	bool good = ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_X, &par->center_mass_x);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_Y, &par->center_mass_y);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA, &par->particleArea);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_TOP, &par->boundingRect.top);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_LEFT, &par->boundingRect.left);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_HEIGHT, &par->boundingRect.height);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_WIDTH, &par->boundingRect.width);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_IMAGE_AREA, &par->particleToImagePercent);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA, &par->particleQuality);

	if (good)
	{
		/* normalized position (-1 to 1) */
		par->center_mass_x_normalized = NormalizeFromRange(par->center_mass_x, par->imageWidth);
		par->center_mass_y_normalized = NormalizeFromRange(par->center_mass_y, par->imageHeight);
	}
}