/**
 * \brief Compute the center of gravity of all pixels
 */
Point	CGFilter::operator()(const ConstImageAdapter<double>& image) {
	BorderFeatherAdapter<double>	feather(image, _radius);
	
	Point	sum;
	double	totalweight = 0;
	int	w = image.getSize().width();
	int	h = image.getSize().height();
	for (int x = 0; x < w; x++) {
		for (int y = 0; y < h; y++) {
			double	v = feather.pixel(x, y);
			if (v != v) {
				continue;
			}
			if (v >= std::numeric_limits<double>::infinity()) {
				continue;
			}
			if (v <= -std::numeric_limits<double>::infinity()) {
				continue;
			}
			sum = sum + Point(x, y) * v;
			totalweight += v;
		}
	}
	return sum * (1. / totalweight);
}
std::vector<Residual>	Analyzer::operator()(const ConstImageAdapter<double>& image) const {
	// first find out whether the patch size fits inside the image
	if ((patchsize > image.getSize().width())
		|| (patchsize > image.getSize().height())) {
		throw std::runtime_error("patch size does not fit into image");
	}

	// build a set of patches
	ImageSize	size = image.getSize();
	int	hsteps = (size.width() - patchsize) / spacing;
	int	xoffset = (size.width() - hsteps * spacing) / 2;
	int	vsteps = (size.height() - patchsize) / spacing;
	int	yoffset = (size.height() - vsteps * spacing) / 2;
	std::vector<ImagePoint>	points;
	for (int h = 0; h <= hsteps; h++) {
		for (int v = 0; v <= vsteps; v++) {
			ImagePoint	point(xoffset + h * spacing,
						yoffset + v * spacing);
			points.push_back(point);
		}
	}

	// now compute the shift for each point
	std::vector<Residual>	result;
	for (auto pt = points.begin(); pt != points.end(); pt++) {
		Residual	residual = translation(image, *pt, patchsize);
		if (residual.valid()) {
			result.push_back(residual);
		}
	}

	// display resulting residuals if in debug mode
	if (debuglevel >= LOG_DEBUG) {
		for (std::vector<Residual>::size_type i = 0; i < result.size();
			i++) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "residual[%d] %s", i,
				std::string(result[i]).c_str());
		}
	}

	return result;
}
/**
 * \brief Perform phase correlation
 *
 * This method performs the phase correlation and constructs a new image
 * if a refresh is needed.
 */
Point	RefreshingTracker::correlate(const ConstImageAdapter<double>& adapter,
		PhaseCorrelator& correlator) {
	Point   offset = correlator(*_image, adapter).first;
	debug(LOG_DEBUG, DEBUG_LOG, 0, "correlate %s with %s -> %s",
		_image->size().toString().c_str(),
		adapter.getSize().toString().c_str(),
		offset.toString().c_str());
	if (refreshNeeded()) {
		refresh(adapter, offset);
	}
	return _offset + offset;
}
/**
 * \brief Construct a FourierTransform from an image adapter
 */
FourierImage::FourierImage(const ConstImageAdapter<double>& image)
	: Image<double>(FourierImage::fsize(image.getSize())),
	  _orig(image.getSize()) {
	Image<double>	i(image);
	fourier(i);
}
示例#5
0
	DeemphasizingAdapter(const ConstImageAdapter<T>& image,
		const ConstImageAdapter<S>& deemph, double degree)
		: ConstImageAdapter<T>(image.getSize()), _image(image),
		  _deemph(deemph), _degree(degree) {
	}