예제 #1
0
Halide::Func ImageConverter(Halide::ImageParam image) {
	// First get min and max of the image
	RDom r(0, image.width(), 0, image.height());

	// Now rescale the image to the range 0..255 and project the value to a RGBA integer value
	Func imgmin;
	imgmin() = minimum(image(r.x, r.y));
	Func imgmax;
	imgmax() = maximum(image(r.x, r.y));
	Expr scale = 1.0f / (imgmax() - imgmin());
	Func rescaled;
	Var x, y;
	Expr val = cast<uint32_t>(255.0f * (image(x, y) - imgmin()) * scale + 0.5f);
	Expr scaled = val * cast<uint32_t>(0x010101);
	rescaled(x, y) = scaled;

	imgmin.compute_root();
	imgmax.compute_root();

	Var xo, yo, xi, yi;

	//rescaled.tile(x, y, xo, yo, xi, yi, 32, 8);
	//rescaled.vectorize(xi);
	//rescaled.unroll(yi);

	return rescaled;
}
예제 #2
0
void NamedWindow::showImage2D(Halide::Image<uint8_t> im)
{
	static Halide::Func convert("convertToMat2D");
	static Halide::ImageParam ip(Halide::UInt(8), 2);
	static Halide::Var x, y;

	if (!convert.defined())
	{
		convert(x, y) = ip(x, y);
		convert.vectorize(x, 4).parallel(y, 4);
	}

	ip.set(im);
	cv::Mat mat(im.height(), im.width(), CV_8UC1, cv::Scalar(0));
	convert.realize(Halide::Buffer(Halide::UInt(8), im.width(), im.height(), 0, 0, mat.data));
	cv::imshow(name, mat);
}
예제 #3
0
void NamedWindow::showImage3D(Halide::Image<float> im)
{
	static Halide::Func convert("convertToMat3D");
	static Halide::ImageParam ip(Halide::Float(32), 3);
	static Halide::Var x, y, c;

	if (!convert.defined())
	{
		convert(c, x, y) = Halide::cast<uint8_t>(ip(x, y, 2 - c) * 255);
		convert.vectorize(x, 4).parallel(y, 4);
	}

	ip.set(im);
	cv::Mat mat(im.height(), im.width(), CV_8UC3, cv::Scalar(0));
	convert.realize(Halide::Buffer(Halide::UInt(8), im.channels(), im.width(), im.height(), 0, mat.data));
	cv::imshow(name, mat);
}
예제 #4
0
파일: Param.cpp 프로젝트: bleibig/Halide
std::string imageparam_repr(h::ImageParam &param)  // non-const due to a Halide bug in master (to be fixed)
{
    std::string repr;
    const h::Type &t = param.type();
    if (param.defined()) {
        boost::format f("<halide.ImageParam named '%s' (not yet defined) >");
        repr = boost::str(f % param.name());
    } else {
        boost::format f("<halide.ImageParam named '%s' of type '%s(%i)' and dimensions %i %i %i %i>");
        repr = boost::str(f % param.name() %
                          type_code_to_string(t) % t.bits() %
                          param.dim(0).extent() %
                          param.dim(1).extent() %
                          param.dim(2).extent() %
                          param.dim(3).extent());
    }
    return repr;
}
예제 #5
0
파일: Param.cpp 프로젝트: bleibig/Halide
void image_param_set(h::ImageParam &param, const h::Buffer<T> &im) {
    param.set(im);
}
예제 #6
0
파일: Param.cpp 프로젝트: bleibig/Halide
h::Buffer<> image_param_get(h::ImageParam &param) {
    return param.get();
}