Skip to content

Instantly share code, notes, and snippets.

@rukku
Created March 9, 2016 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rukku/7fb23b4760a1cf1b92cd to your computer and use it in GitHub Desktop.
Save rukku/7fb23b4760a1cf1b92cd to your computer and use it in GitHub Desktop.
from numpy import flipud
from numpy import zeros
import matplotlib.image
image_dn = zeros([494,659], dtype = float) #image size
filename = r'image_150529_123155_0x79_HPCM_750nm_659x494_complete.bin' #directory + filename ng bin
def binToInt(astring):
temp = ' '.join(format(ord(i),'b').zfill(8) for i in astring)
temp = temp[0:8]+temp[9:17]
temp = int(temp,2)
return temp
with open(filename, "rb") as f:
f.seek(89)
svt = f.read(2)
svt = float(binToInt(svt))
sht = f.read(2)
sht = float(binToInt(sht))
expT = (0.03337*svt)+(524-sht)*(0.00006356)+(487/780)*(0.00006356)
f.seek(95)
gain = f.read(2)
gain = binToInt(gain)
f.seek(651314)
wavelenght = f.read(2)
wavelenght = binToInt(wavelenght)+650
f.seek(206) #start ng image data after header
for i in range(0,494):
for j in range(0,659):
data = f.read(2)
data = binToInt(data)
image_dn[i,j]=data
print "Wavelength = "+str(wavelenght)+"\n"+"Exposure time = "+str(expT)+" s"+"\n"+"Gain = "+str(gain)
image_dn = flipud(image_dn)
matplotlib.image.imsave("img_750.tif", image_dn, cmap="gray", format="tif") #bin to image file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment