9

I'm working on processing .raw image files, but I'm not sure how the image is being stored. Each pixel is a unsigned 16-bit value, with typical values ranging from 0 to about 1000 (in integer form). This isnt enough bits for hex values, and its not RGB (0-255) so I'm not quite sure what it is.

Bonus: if you have any idea on how to convert this to grayscale in OpenCV (or just mathematically) that would be a huge help too.

andrw
  • 790
  • 1
  • 8
  • 20
  • 2
    Well, where did you get that image? Because there are hundreds of raw formats. – user703016 Jun 30 '11 at 18:03
  • First of all, you haven't said *which* format (and version), as there are several. Second, I'd recommend using an existing library. Processing RAW image files is no easy task as often these values need additional processing to produce an image. The formats can be slightly different even from between different camera models of the same manufacturer. There's a reason why most of these programs/libraries are proprietary and cost money. – DarkDust Jun 30 '11 at 18:07
  • I got these images from my internship at a small company, and they're not sure how these values correlate to colors either. All they know is it works in matlab, but they want me to re-code it in C++. I'm learning to use OpenCV to do processing, but viewing the image in OpenCV gives a very black image, with only a few areas of dark gray and white. The opencv image resembles the actual image, but in much darker shades. – andrw Jun 30 '11 at 18:13

3 Answers3

12

The name RAW comes from the fact that the values stored in the file are not pixel RGB values, but the raw values that were measured from the camera itself. The values have meaning only if you know how the camera works. There are some standards, but really, you should just consider RAW to be a collection of poorly defined, undocumented, proprietary formats that probably won't intuitively match any idea you have about how images are stored.

Check out DCRaw -- it's the code that nearly every program that supports RAW uses

https://www.dechifro.org/dcraw/

The author reverse-engineered and implemented nearly every proprietary RAW format -- and keeps it up to date.

Warty
  • 7,237
  • 1
  • 31
  • 49
Lou Franco
  • 87,846
  • 14
  • 132
  • 192
3

The other answers are correct, RAW is not a standard, it's shorthand. Camera CCDs often do not have separate red, green and blue pixels for each pixel, instead, they will use what's called a Bayer Pattern and then only save the pixel values for that pattern. Then, you will need to convert that pattern to rgb values.

Also, for the bonus question, if you are simply trying to convert a RGB image to grayscale, or something like that, you can either use the matrix operators, or call convertTO

Jeffeb3
  • 111
  • 1
  • 6
1

Forgot what the R/G/B of 16-bit was:

"there can be 5 bits for red, 6 bits for green, and 5 bits for blue"

http://en.wikipedia.org/wiki/Color_depth#16-bit_direct_color

Seen it used in game code before.

Complete shot in the dark though being as there are also proprietary RAW formats.

StrangeWill
  • 2,106
  • 1
  • 23
  • 36