1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonでtifから複数枚の画像を保存する方法

Last updated at Posted at 2022-03-11

TIFF形式に含まれる複数の画像を一枚一枚取り出して保存する方法を扱います.

import cv2
from tifffile import TiffFile
import numpy as np

tifpath = "./hoge.tif" # tifファイルのパス
imgpath = "./folder/" # 画像ファイルを保存したいフォルダのパス

with TiffFile(tifpath) as tif:
    mmap = tif.asarray(out="memmap")

# 最初の画像から順番に保存
for i in range(len(mmap)):
	img = np.asarray(mmap[i])
	img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
	#4ケタの0埋めでファイル名をつける
	cv2.imwrite("{0:s}{1:04d}.png".format(imgpath, i+1),img) #"png"は適宜変更 

以上です.

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?