まずは読み込みクラス。numpy配列で出力。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os.path
import numpy
from PIL import Image
class data_get:
def __init__(self):
return
"""
(Purpose)
tiffファイルからデータ部分を抜き出す
in :filename 入力ファイルパス
out:outdata 出力配列(2次元のnumpy)
(History)
2017/11/30 作成
"""
def get_tiff_data(self, filename):
# 拡張子確認
root, ext = os.path.splitext(filename)
if ext in ['.tif','.tiff']:
# TIFFファイル取り込み 配列化
img = Image.open(filename)
ar_width, ar_height = img.size
outdata = img.getdata()
outdata = numpy.reshape(outdata, (ar_height, ar_width))
else:
return None
return outdata
