TIL
[TIL] Python Convert multiple 2d img to 3d arr
hu-nie
2022. 10. 13. 17:31
Voxel 개념의 3D 데이터가 2D형태의 이미지 여러장으로 저장된 경우 3d array 형태로 바꾸어 주는 방법
from pathlib import Path
import numpy as np
from PIL import Image
from tqdm.auto import tqdm
paths = list(Path("file_path").rglob("*.이미지 확장자"))
images = []
for path in tqdm(paths):
img = Image.open(path)
# img = Image.open(path).convert("L")
# img = Image.open(path).convert("RGB")
images.append(img)
data = np.stack(images)