Took me hours before I found and read the documentation.
CImg stores pixels in a planer format (RRRR…..GGGG…..BBBB). For most tasks in CUDA, it’s much better to store the pixel values in the interleaved format (RGBRGBRGB……).
In order to do that, just call the permute_axes method of the CImg object:
CImg image("image.jpg"); image.permute_axes("cxyz");
After permutation, the width, height, spectrum and depth values that are reported for CImg will all change. To permute back (for displaying or saving) do this:
CImg result(dataPointer, spectrum, width, height, depth, false); result.permute_axes("yzcx");
Where the values, are previously saved values (before doing any kind of permutation on the axes). This will undo any changes and now you can safely save the image or display it.
CImg instance from interleaved array (bitmap):
Now imagine you want to initialize a CImg object with an interleaved bitmap (say an OpenGL texture or what have you). In this case, you need to know the width and height of the image as well as the number of components. Also imagine that the spectrum is 1. To create a CImg object using this array you can do (
imageArray is the bitmap pointer):
cimg_library::CImg<unsigned char> result(imageArray, numChannels, imageWidth, imageHeight, 1, true); result.permute_axes("yzcx");
If I have a data buffer that has interleaved RGBA data, would I use the same:
I don’t have a good mental model of what this string does. How is this converting from RGB (or RGBA) to planar data?