Skip to content

Instantly share code, notes, and snippets.

@toshinoritakata
Created February 4, 2014 09:34
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 toshinoritakata/8800627 to your computer and use it in GitHub Desktop.
Save toshinoritakata/8800627 to your computer and use it in GitHub Desktop.
Mentalrayのnormal画像(32bit float)を読み込む
def read_image(img_file):
with open(img_file, 'rb') as img:
(format, nll, xres, yres, verson) = unpack('>BBHHH', img.read(8))
pixels = np.zeros([yres, xres, 3]) # y,xでアクセスする
for iy in range(yres):
line = unpack('>{0}f'.format(xres*3), img.read(4*xres*3))
for lx, ix in enumerate(range(0, xres*3, 3)):
pixels[iy][lx] = line[ix:ix+3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment