working with raw image files

MRAB python at mrabarnett.plus.com
Tue Jun 14 16:26:28 EDT 2011


On 14/06/2011 21:13, kafooster wrote:
> 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))
> imshow(data[:,:,40],cmap='gray')
> show()
>
> 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?

Multiply the numpy array by a scaling factor, which is
float(max_8bit_value) / float(max_16bit_value).



More information about the Python-list mailing list