Esempio n. 1
0
	// Minimal mock of VW imageio routines
	void ReadImage(const std::string& file, ImageRGB<byte>& image) {
		CHECK_PRED1(fs::exists, file);
		bool jpeg = IsJpegFilename(file);

		// Get size
		point2<ptrdiff_t> size;
		if (jpeg) {
			size = jpeg_read_dimensions(file);
		} else {
			size = png_read_dimensions(file);
		}

		// Allocate image data
		image.AllocImageData(size.x, size.y);
		rgba8_view_t v = interleaved_view(image.GetWidth(),
																			image.GetHeight(),
																			(rgba8_pixel_t*)image.GetImageBuffer(),
																			image.GetWidth()*sizeof(PixelRGB<byte>));

		// Load the image
		if (jpeg) {
			jpeg_read_and_convert_view(file, v);
		} else {
			png_read_and_convert_view(file, v);
		}

		// GIL uses 255=opaque but we use 0=opaque
		InvertAlpha(image);
	}
void MatlabArrayToImage(const mxArray* m, ImageRGB<byte>& image) {
	CHECK(mxIsDouble(m)) << "Only images of double type are supported at present";
	VecI dims = GetMatlabArrayDims(m);
	CHECK_EQ(dims.Size(), 3) << "MatlabArrayToImage expects a H x W x 3 array";
	CHECK_EQ(dims[2], 3) << "MatlabArrayToImage expects a H x W x 3 array";
	image.AllocImageData(dims[1], dims[0]);
	double* p = mxGetPr(m);
	for (int x = 0; x < dims[1]; x++)
		for (int y = 0; y < dims[0]; y++)
			image[y][x].r = *p++ * 255;  // pixels of type double are in [0,1] under matlab
	for (int x = 0; x < dims[1]; x++)
		for (int y = 0; y < dims[0]; y++)
			image[y][x].g = *p++ * 255;  // pixels of type double are in [0,1] under matlab
	for (int x = 0; x < dims[1]; x++)
		for (int y = 0; y < dims[0]; y++)
			image[y][x].b = *p++ * 255;  // pixels of type double are in [0,1] under matlab
	for (int x = 0; x < dims[1]; x++)
		for (int y = 0; y < dims[0]; y++)
			image[y][x].alpha = 0;
}