Sample DICOM 로딩 샘플 코드

sample image show

Sample DICOM 이미지 로드 및 미리보기

  • DICOM이미지는 의학용 이미지를 다룰때 쓰임
In [1]:
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

import os
print(os.listdir("../input"))
['dicom-images-test', 'dicom-images-train', 'sample images', 'sample_submission.csv', 'train-rle.csv']
In [2]:
import os
import pydicom
import glob
from PIL import Image
import matplotlib.pyplot as plt
In [3]:
inputdir = '../input/sample images/'
outdir = './'

fig, axs = plt.subplots(2, 5, figsize=(30, 10))
test_list = [os.path.basename(x) for x in glob.glob(inputdir + './*.dcm')]
for f,ax in zip(test_list,axs.flatten()):  
    ds = pydicom.read_file( inputdir + f) # read dicom image
    img = ds.pixel_array # get image array
    img_mem = Image.fromarray(img)
    ax.imshow(img_mem)