text_html_output_1.png
from tensorflow.keras.preprocessing.image import load_img, img_to_array

from tqdm.notebook import tqdm

import cv2

import numpy as np

import os

import pandas as pd

import pydicom

train_name = os.listdir('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train')
test_name = os.listdir('../input/rsna-miccai-brain-tumor-radiogenomic-classification/test')

labels = pd.read_csv('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train_labels.csv')
labels

def load_dicom(path):
    dicom = pydicom.read_file(path)
    data = dicom.pixel_array
    data = data - np.min(data)
    if np.max(data) != 0:
        data = data / np.max(data)
    data = (data * 255).astype(np.uint8)
    return data

path0 = '../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00000/T1wCE/Image-1.dcm'
img1 = load_dicom(path0)
img2 = cv2.resize(img1, (9, 9))

train_dir = '../input/rsna-miccai-brain-tumor-radiogenomic-classification/train'
trainset = []
trainlabel = []
trainidt = []
for i in tqdm(range(len(labels))):
    idt = labels.loc[i, 'BraTS21ID']
    idt2 = ('00000' + str(idt))[-5:]
    path = os.path.join(train_dir, idt2, 'T1wCE')
    for im in os.listdir(path):
        img = load_dicom(os.path.join(path, im))
        img = cv2.resize(img, (9, 9))
        image = img_to_array(img)
        image = image / 255.0
        trainset += [image]
        trainlabel += [labels.loc[i, 'MGMT_value']]
        trainidt += [idt]