Пример #1
0
void ImageSaliencyDetector::compute() {
	if (mSrcImage.empty()) {
		throw std::logic_error("ImageSaliencyDetector: Source image is empty!");
	}

	srand(static_cast<unsigned int>(time(NULL)));

	// Get edge information
	EdgeDetector canny;
	canny.compute(mSrcImage);
	setMagnitudes(canny.getGradMagnitudes());
	setOrientations(canny.getGradOrientations());

	// Quantize magnitudes
	quantizeMagnitudes();

	// Perform iterative saliency detection mechanism
	int squaredNHood = neighborhoodSize * neighborhoodSize;
	int halfNHood = neighborhoodSize / 2;
	int reqNumSamples = static_cast<int>(samplingPercentage * (mSrcImage.cols * mSrcImage.rows * squaredNHood));
	int imageHeight = mSrcImage.rows;
	int imageWidth = mSrcImage.cols;
	int counter = 0;

	while (counter < reqNumSamples) {
		KernelDensityInfo kernelSum;
		BoundingBox2D bounds;
		std::vector<Location2D> samples(4);

		// Randomly select the location of the first sample
		samples[0].y = rand() % imageHeight;
		samples[0].x = rand() % imageWidth;

		// The other 3 samples MUST be selected in the neighborhood of the first
		samples[1].y = (rand() % neighborhoodSize) + (samples[0].y - halfNHood);
		samples[1].x = (rand() % neighborhoodSize) + (samples[0].x - halfNHood);

		samples[2].y = (rand() % neighborhoodSize) + (samples[0].y - halfNHood);
		samples[2].x = (rand() % neighborhoodSize) + (samples[0].x - halfNHood);

		samples[3].y = (rand() % neighborhoodSize) + (samples[0].y - halfNHood);
		samples[3].x = (rand() % neighborhoodSize) + (samples[0].x - halfNHood);

		kernelSum = calculateKernelSum(samples);
		bounds = getApplicableBounds(samples);
		updateApplicableRegion(bounds, kernelSum);

		++counter;
	}

	updateSaliencyMap();
}
Пример #2
0
void Matrix44F::setFrontOrientation(const Vector3F& front)
{
    Vector3F side = front.perpendicular();
    Vector3F up = front.cross(side);
    setOrientations(side, up, front);
}