Hello I am using the Python Imaging Library to make a small conversion to an image. The image is a raw binary file with 16 bit unsigned integers. For some reason I cannot get python to work it keeps giving me the following error:
Traceback (most recent call last):
File "C:\Users\Patrick\workspace\colorCorrect\src\editGrayscale.py", line 24, in <module>
changed.save(saveFile)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1423, in save
raise KeyError(ext) # unknown extension
KeyError: '.bin'
My code is as follows:
import Image
#file to save: C:\Users\name\imagedata\visiblespec.bin
fileName = raw_input("Enter a file name: ")
saveFile = raw_input("Enter a new save file name: ")
with open(fileName, 'rb') as f:
im = Image.fromstring('L', (3032, 2016), f.read()) # also try 'L;16B', 'I;16', and 'I;16B'
changed = im.point(lambda i: i/2)
changed.save(saveFile)
Again my image is a grayscale 16 bit unsigned integers around 11 mbs and written in hexadecimal.
Thanks!
UPDATE:
Code that worked to save file:
def save(filename, contents):
fh = open(filename, 'w')
fh.write(contents)
fh.close()
save(saveFile, final)