Skip to content
Industries
Products
Test Lab
Training & Events
Resources
Company
Contact
Contact

Converting Bit-Stream Images

Tech-Notes

Converting Bit-Stream Images

Ready to Transform Your Vision?

Discover how our precision testing solutions can elevate your imaging projects.

Need help with

image quality testing?

Our team of experts is ready to help you achieve the best results for your imaging applications.

Phone (DE): +49 2273 99 99 1-0
Phone (USA): +1 786 686-8664
Phone (China): +86 158 8961 9096
Office Hours: Mon–Fri, 9–5 PM (CET)
Contact Us
Image Engineering
lens with aperture - standard image

05 May 2012

In this TechNote we would like to present three ways to convert a raw (bit-stream) image into a conventional image file format. In this case we define a raw image as a series of bits. The .raw file contains only information about the image pixel values, there’s no header and no additional information included (in contrast to the camera raw files e.g. CR2, NEF, ARW, ORF, RAF etc.).

THE RAW FILE

As a sample image, we consider a 1280x800 grayscale image (8 bit). Because there is no additional information, each byte represents the gray value of one pixel. The .raw file opened in a hex-editor would look like the following.

figure 1: .raw file opend in hex editor

In the editor the file is represented by 1.024.000 (=1280*800) hexadecimal values. Because the counting starts at 0x00000, the last value 03 is at position 0xF9FFF (which is 1.023.999 in hexadecimal form). The bits are sorted line by line.

HOW TO CONVERT RAW IMAGES

There are many different ways to convert bit-stream images, we would like to present at least three. To be able to convert these .raw files two things must be known: the width and height of the image and the bit depth. As already mentioned, our file is a 1280x800 grayscale image (8 bit).

VIA PHOTOSHOP / IMAGE

fig 2: Adobe Photoshop raw
fig 2: Adobe Photoshop raw
   fig 3: ImageJ raw import
fig 3: ImageJ raw import

The conversion via Adobe Photoshop and ImageJ is similar. We have to enter the image dimension and the bit depth. In Photoshop we have to enter the amount of channels in a separate edit field, whereas in ImageJ the pop-up menu “Image type” combines the bit depth and amount of channels. If the .raw files include a header you can choose an offset of several bytes to get access to the image data. After that, the images can be saved in any supported format.

VIA IMAGEMAGICK

fig 4: ImageMagick  convert via comandline

ImageMagick maintains simple command-line processing for converting raw files. The executable “convert.exe” needs some flags:

-size 1280x800 (our image size)

-depth 8 (8bit/channel)

GRAY: <raw image path/filename> <converted image path/filename>

The “Explicit Image Format” GRAY identifies our image as a grayscale image, because the .raw extension does not specify a known format and has no header information. The output format can be chosen as you like, in this case we choose TIF. (type –help for more information)

THE CONVERTED IMAGE

fig 5: original image (left), crop (right)

The converted image will look like figure 5 left. If we take some sample values from the image e.g. row 96 and column 584 to 586, we can check if the bytes in the .raw file have the same values.

fig 6: .raw file in hex editor

The position of these sample values in hex code would be at 0x1E248 to 0x1E24A (<width> <current row> + <current column> = 128096+584...585...586). As we can see, the values are the same:

(hex -> dec)
4E -> 78
AB -> 171
52 ->82

ck