0

I have a bizarre .raw file in the following format, that I need to open for a class project. It has the following structure using the example of a 487x414 photo:

  • The number of rows is two un-signed bytes (01E7)
  • The number of columns is two un-signed bytes (019E)
  • The number of bits representing each pixel (this will always be 8)
  • The actual picture data

The project is to run edge detection on the .raw file, but the professor said I should be able to open it with any old image editing software (apparently, he expects me to be prompted with a window where I set the number of bytes in the header), so I tried the following to no avail:

  • Paint.net
  • Photoshop Elements
  • Adobe Lightroom
  • ImageMagick
  • Gimp
  • DCRaw

I'm dual booting Ubuntu and Windows, so if anyone has any ideas on how I could get this file displayed, (I'm currently trying to load it into OpenCV as a histogram, but I would like to have something to check my result against), it would be greatly appreciated.

2
  • Try ufraw. I use it to edit raw files from my camera (nikon) and as far as I'm aware it has support for most other formats. Has to be worth a try.
    – Holloway
    Commented Jul 21, 2014 at 13:48
  • I did try that, but unfortunately it didn't work. Thanks for reminding me of this unanswered question.
    – Seanny123
    Commented Jul 21, 2014 at 16:47

1 Answer 1

0

I ended up having to write a custom Python script which you can find here. Here's the important part.

#Load the raw file
f = open(filename,'rb') # switch to command line args later
#Because the byte order is weird
a = f.read(1)
b = f.read(1)
#First line is rows
rows = int((b+a).encode('hex'), 16)
a = f.read(1)
b = f.read(1)
#Second line is columns
cols = int((b+a).encode('hex'), 16)
#Last byte is encoding, but we're just going to ignore it
f.read(1)
#And everything else is 8 bit encoded, so let's load it into numpy and display it with matplotlib
bin_image = np.fromstring(f.read(), dtype=np.uint8)
#Change the shape of the array to the actual shape of the picture
bin_image.shape = (cols, rows)

fig = pylab.figure()
#Display the original image
fig.add_subplot(1,4,1)
pylab.imshow(bin_image, cmap=cm.gray)
1
  • If this worked, mark it as accepted to remove this question from unanswered.
    – Holloway
    Commented Jul 22, 2014 at 7:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .