Created
August 28, 2017 08:48
-
-
Save buxtonpaul/c41cf1f3c9a0eb1927628ae3bc86bfc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import scipy.misc | |
import png | |
#import pil | |
import matplotlib.image as mpimg | |
def write_pgm(image, filename): | |
""" Write grayscale image in PGM format to file. | |
""" | |
height, width = image.shape | |
maxval = 65536 #= image.max() | |
with open(filename, 'w') as f: | |
f.write('P5 {} {} {}\n'.format(width, height, maxval)) | |
image.tofile(f) | |
fnames = [ | |
'CC_A', | |
'CC_CWF', | |
'CC_D65', | |
'CC_HOR', | |
'CC_TL84', | |
'FF_A', | |
'FF_CWF', | |
'FF_D65', | |
'FF_HOR', | |
'FF_TL84', | |
'dark' | |
] | |
pathname = 'd:/Downloads/' | |
dt = np.dtype('uint16') | |
width = 4056 | |
height = 3040 | |
for f in fnames: | |
infile = pathname+f+'_unpacked.raw' | |
x=np.fromfile(infile,dtype=dt).reshape ((height,width)) | |
print (x.max()) | |
if isPNG: | |
outfile = pathname+f+'.png' | |
with open(outfile, 'wb') as fout: | |
writer = png.Writer(width=x.shape[1], height=x.shape[0], bitdepth=16, greyscale=True) | |
zgray2list = x.tolist() | |
writer.write(fout, zgray2list) | |
else: | |
outfile = pathname+f+'.pgm' | |
write_pgm(x,outfile) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment