working with raw image files



Ok, I solved the problem with matplotlib

fileobj = open("hand.raw", 'rb')
data = numpy.fromfile(fileobj,dtype=np.uint16)
data = numpy.reshape(data,(96,470,352))

the error was caused by different order of data, however it still
reads the dataset as half of it size. whatever.

please leave the part about .raw, lets just start thinking of it from
level of numpy array.

I would like to visualize this data with PIL, but PIL works only with
8bit data. How could I resample my array from 16bit to 8bit?

Why bother? NumPy is a much better image-processing library than PIL. The
only reason I use PIL is for its import/export routines.

If you are going to use PIL, apply any corrections (gamma correction,
histogram equalisation, etc) before reducing the data to 8 bits.



Dave Angel

well, I am only working with grayscale MRI medical images(mainly 8 or
16bits), saved as .raw. I do not need to worry about rgb.

Well, since you've already gotten results you like (per another msg from
you), the gamma adjustment must already be made. So they're an entirely
different meaning of raw than used by DSLR's, for example.

Glad it's working for you.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question