1

s it possible to:

read an image given by just a filename (not knowing the image format) to a 2d matrix rgb uncompressed form (e.g. read an JPG to a 2d array) access the bytes of that image, copy them, change them... (e.g. inverse the colors, I need a pointer to the image bytes, setters/getters won't do )

rgb8_image_t img;
jpeg_read_image ("lena.jpg",img);

i use these to load the image. now how do i access the pixels or bytes of this image?

mloskot
  • 37,086
  • 11
  • 109
  • 136
user3275596
  • 31
  • 1
  • 6
  • I did know that lib before, but it looks like (if you read image.hpp) that you have to use a 'view' to get access to the image data [ex](http://www.boost.org/doc/libs/1_56_0/libs/gil/doc/html/giltutorial.html#ImageViewTransformationSec). – alexbuisson Aug 21 '14 at 12:14
  • do you have any kind of sample code which can help. there is no sample code in boost documentation in order to get as idea as to where to start and where to end – user3275596 Aug 21 '14 at 12:25
  • Actually @alexbuisson posted a link to sample code, maybe you missed it because it was just called "ex": http://www.boost.org/doc/libs/1_56_0/libs/gil/doc/html/giltutorial.html#ImageViewTransformationSec – ypnos Aug 21 '14 at 13:05
  • thankyou @ypnos i did see there i am just a novice and i am getting very confused with it. I would really appretiate it if there was a much simpler example to understand. – user3275596 Aug 21 '14 at 13:08

1 Answers1

1

Here is a sample that sets G component of all pixels to 128

rgb8_image_t img;
const rgb8_view_t & mViewer = view(img);
for (int y = 0; y < mViewer.height; ++y)
{
  rgb8_view_t::x_iterator trIt = mViewer.row_begin(y);
  for (int x = 0; x < mViewer.width; ++x)
    at_c<1>(trIt[x]) = 128;
}
Andrey Nekrasov
  • 456
  • 2
  • 12