tags:

views:

30

answers:

1

Hi guys,

I'm having some trouble figuring out the boost image library.

I could not find any exact documentation on how to use the interleaved_view function included in the boost::gil library. More specifically, I don't know exactly what binary format the raw data is supposed to be stored in.

The only mention of it I could find was in the gil tutorial:

// Calling with 8-bit RGB data into 16-bit BGR
void XGradientRGB8_BGR16(const unsigned char* src_pixels, ptrdiff_t src_row_bytes, int w, int h,
                                 signed short* dst_pixels, ptrdiff_t dst_row_bytes) {
    rgb8c_view_t  src = interleaved_view(w,h,(const rgb8_pixel_t*)src_pixels,src_row_bytes);
    rgb16s_view_t dst = interleaved_view(w,h,(    rgb16s_pixel_t*)dst_pixels,dst_row_bytes);
    x_gradient(src,dst);
}

Also, the function prototype says

template<typename Iterator>
type_from_x_iterator< Iterator>::view_t     
boost::gil::interleaved_view (std::size_t width, std::size_t height, Iterator pixels, std::ptrdiff_t rowsize_in_bytes)
//Constructing image views from raw interleaved pixel data. 

My question is, what exactly is the format gil expects in the binary format, and what is rowsize_in_bytes supposed to be?

The only time I've seen an interleaved image before is when working with OpenGL, which was just RGB information for each pixel stored next to each other. I thought rowsize_in_bytes would just literally the size of a row of pixels in bytes, so I tried to write a PNG with this:

void makeImage(const string fileName, const unsigned char * src, const int w, const int h) {
    rgb8c_view_t outImage = interleaved_view(w,h, (const rgb8_pixel_t*) src, w*3*sizeof(unsigned char));
    boost::gil::png_write_view(fileName,outImage);
}

and the input src was an flat array of size w*h, of format

(char)R, (char)G, (char)B, (char)R, (char)G, (char)B, (char)R, (char)G, (char)B ...

The image was of just a white box on a black background. However, the results I got were rather... strange

Results

If anyone has any idea why this happened, and how interleaved_view actually works, that'd be great. Thanks in advance!

EDIT: Sorry guys, I just realized my dumb mistake. I got it working now... :( The problem wasn't with the format of the image, but rather that it was row major, and not column major

+1  A: 

Sorry guys, I just realized immediately after posting that I've been working with matlab for way too long... I wrote the array in column major form... Ugh I feel stupid

Xzhsh
+1 for admitting your error and writing an answer about it. Don't worry, other people might make the same mistake and consider this helpful.
schnaader