Created
February 4, 2014 09:34
-
-
Save toshinoritakata/8800627 to your computer and use it in GitHub Desktop.
Mentalrayのnormal画像(32bit float)を読み込む
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
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