Skip to content
Snippets Groups Projects
Commit 81733ef1 authored by cordina's avatar cordina
Browse files

Upload New File

parent 787de3c9
No related branches found
No related tags found
3 merge requests!3Upload New File,!2Upload New File,!1Draft: Upload New File
%% Cell type:code id: tags:
``` python
!pip install pydicom
import matplotlib.pyplot as plt
import pydicom
from pydicom.data import get_testdata_file
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from pathlib import Path
import os
import json
import glob
import random
import collections
import cv2
import pandas as pd
import pydicom
from pydicom.pixel_data_handlers.util import apply_voi_lut
from tqdm.notebook import tqdm
import os
import glob
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score, accuracy_score, log_loss
from scipy import ndimage
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.utils import to_categorical
from tensorflow.keras import layers
from matplotlib import animation, rc
rc('animation', html='jshtml')
```
%% Cell type:code id: tags:
``` python
path_data="/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/"
train_df = pd.read_csv(path_data+"train_labels.csv")
def load_dicom(path):
dicom = pydicom.read_file(path,force=True)
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
def visualize_sample(
brats21id,
slice_i,
mgmt_value,
types=("FLAIR", "T1w", "T1wCE", "T2w")
):
plt.figure(figsize=(10, 3))
patient_path = os.path.join(
path_data+"train/",
str(brats21id).zfill(5),
)
for i, t in enumerate(types, 1):
t_paths = sorted(
glob.glob(os.path.join(patient_path, t, "*")),
key=lambda x: int(x[:-4].split("-")[-1]),
)
data = load_dicom(t_paths[int(len(t_paths) * slice_i)])
plt.subplot(1, 4, i)
plt.imshow(data, cmap="gray")
plt.title(f"{t}", fontsize=10)
plt.axis("off")
plt.show()
def create_animation(ims):
fig = plt.figure(figsize=(5, 5))
plt.axis('off')
im = plt.imshow(ims[0], cmap="gray")
def animate_func(i):
im.set_array(ims[i])
#return [im]
return animation.FuncAnimation(fig, animate_func, frames = len(ims), interval = 1000//4)
def load_dicom_line(path):
t_paths = sorted(
glob.glob(os.path.join(path, "*")),
key=lambda x: int(x[:-4].split("-")[-1]),
)
images = []
for filename in t_paths:
data = load_dicom(filename)
if data.max() == 0:
continue
images.append(data)
return images
def create_animation(ims):
fig = plt.figure(figsize=(5, 5))
plt.axis('off')
im = plt.imshow(ims[0], cmap="gray")
def animate_func(i):
im.set_array(ims[i])
#return [im]
return animation.FuncAnimation(fig, animate_func, frames = len(ims), interval = 1000//4)
def load_dicom_line(path):
t_paths = sorted(
glob.glob(os.path.join(path, "*")),
key=lambda x: int(x[:-4].split("-")[-1]),
)
images = []
for filename in t_paths:
data = load_dicom(filename)
if data.max() == 0:
continue
images.append(data)
return images
create_animation(load_dicom_line("../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00176/T2w"))
```
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment