-1

I'm trying to find a way to get out the rgb values from every pixel in an image. If I had a 3x3 image, what i'm trying to get as an output is something like this:

{
   "0-0": [125,222,0],
   "0-1": [125,222,0],
   "0-2": [125,222,0],
   "1-0": [125,222,0],
   "1-1": [125,222,0],
   "1-2": [125,222,0],
   "2-0": [125,222,0],
   "2-1": [125,222,0],
   "2-2": [125,222,0]
}

I know this a kinda vague question that will propbly be flagged but imma throw it there.

Thanks and cheers

Mitch Kroska
  • 325
  • 4
  • 15
  • Which libraries / programming language you intend to use? – Miki Nov 11 '16 at 09:14
  • 1
    you're right too vague/broad/unclear so +Close for now. Add specifics like What language/OS/gfx lib? also arrays are not usually indexed by strings. There are many ways to do this 1. use 3th party lib 2. write own decoder 3. use in-build functions of your compiler/IDE/OS platform. If you want to write own decoder then JPEG is a bit too much for a rookie to code and BMP has too many variations so I would decode just a specific format of BMP (like unpacked 24bit RGBA or what ever) and convert any images you need to such format. – Spektre Nov 11 '16 at 09:15
  • take a look at this [opening image file on c++ , PNG , JPEG](http://stackoverflow.com/a/37340970/2521214) it is and VCL/C++ example of loading multiple image types using #1,#2 with present code for PCX decoding so you can see how it looks like ... for PNG is used LIBPNG, for BMP,JPEG compiler/IDE in-build function and all the rest has my own decoders (only PCX code present in example) – Spektre Nov 11 '16 at 09:18
  • @Spektre there's no need to code the image loading. You can use Python PIL / C++ [stb_image](https://github.com/nothings/stb/blob/master/stb_image.h) / OpenCV / Matlab or whatever... Then scanning the image and produce that output is rather trivial. It just depends on which libraries/language the OP's using. – Miki Nov 11 '16 at 09:25
  • @Miki The code is a bit older then Python PIL .. anyway 3th party lib is not always an option due to compatibility,legislative,performance,and other reasons (like bugs in decoding encoding nice example is GIF ... in the old days it was legislative problems and now most decoders are buggy ...). – Spektre Nov 11 '16 at 09:28
  • @Spektre sure, but reinventing the wheel is not a good idea in general. Anyhow... until the OP puts some constraints this "discussion" is pretty useless ;D – Miki Nov 11 '16 at 09:34

1 Answers1

0

It is actually very simple to do (and yet hard). You need to get a decoder for each image format you are interested in. Then you need to decode the image. Then you need to print out the pixel values returned by the decoder.

In many cases, you can do this directly from the data saved in a BMP file. However, come BMP files are RLE encoded, and would make this impossible.

user3344003
  • 20,574
  • 3
  • 26
  • 62