Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MALIS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
radjou
MALIS
Commits
81733ef1
Commit
81733ef1
authored
3 years ago
by
cordina
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
787de3c9
No related branches found
Branches containing commit
No related tags found
3 merge requests
!3
Upload New File
,
!2
Upload New File
,
!1
Draft: Upload New File
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Notebook_EDA.ipynb
+1
-0
1 addition, 0 deletions
Notebook_EDA.ipynb
with
1 addition
and
0 deletions
Notebook_EDA.ipynb
0 → 100644
+
1
−
0
View file @
81733ef1
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install pydicom\nimport matplotlib.pyplot as plt\nimport pydicom\nfrom pydicom.data import get_testdata_file\n\n \nimport numpy as np\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom pathlib import Path\n\nimport os\nimport json\nimport glob\nimport random\nimport collections\nimport cv2\nimport pandas as pd\nimport pydicom\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nfrom tqdm.notebook import tqdm\nimport os\nimport glob\n\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import roc_auc_score, accuracy_score, log_loss\n\nfrom scipy import ndimage\n\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras import layers\n\nfrom matplotlib import animation, rc\nrc('animation', html='jshtml')\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-20T21:44:06.129718Z","iopub.execute_input":"2022-01-20T21:44:06.130093Z","iopub.status.idle":"2022-01-20T21:44:22.635619Z","shell.execute_reply.started":"2022-01-20T21:44:06.130004Z","shell.execute_reply":"2022-01-20T21:44:22.634807Z"},"trusted":true},"execution_count":1,"outputs":[]},{"cell_type":"code","source":"path_data=\"/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/\"\ntrain_df = pd.read_csv(path_data+\"train_labels.csv\")\ndef load_dicom(path):\n dicom = pydicom.read_file(path,force=True)\n data = dicom.pixel_array\n data = data - np.min(data)\n if np.max(data) != 0:\n data = data / np.max(data)\n data = (data * 255).astype(np.uint8)\n return data\n\n\ndef visualize_sample(\n brats21id, \n slice_i,\n mgmt_value,\n types=(\"FLAIR\", \"T1w\", \"T1wCE\", \"T2w\")\n):\n plt.figure(figsize=(10, 3))\n patient_path = os.path.join(\n path_data+\"train/\", \n str(brats21id).zfill(5),\n )\n for i, t in enumerate(types, 1):\n t_paths = sorted(\n glob.glob(os.path.join(patient_path, t, \"*\")), \n key=lambda x: int(x[:-4].split(\"-\")[-1]),\n )\n data = load_dicom(t_paths[int(len(t_paths) * slice_i)])\n plt.subplot(1, 4, i)\n plt.imshow(data, cmap=\"gray\")\n plt.title(f\"{t}\", fontsize=10)\n plt.axis(\"off\")\n plt.show()\n\n\n\n\ndef create_animation(ims):\n fig = plt.figure(figsize=(5, 5))\n plt.axis('off')\n im = plt.imshow(ims[0], cmap=\"gray\")\n\n def animate_func(i):\n im.set_array(ims[i])\n #return [im]\n return animation.FuncAnimation(fig, animate_func, frames = len(ims), interval = 1000//4)\n\ndef load_dicom_line(path):\n t_paths = sorted(\n glob.glob(os.path.join(path, \"*\")), \n key=lambda x: int(x[:-4].split(\"-\")[-1]),\n )\n images = []\n for filename in t_paths:\n data = load_dicom(filename)\n if data.max() == 0:\n continue\n images.append(data)\n \n return images\n\n\ndef create_animation(ims):\n fig = plt.figure(figsize=(5, 5))\n plt.axis('off')\n im = plt.imshow(ims[0], cmap=\"gray\")\n\n def animate_func(i):\n im.set_array(ims[i])\n #return [im]\n return animation.FuncAnimation(fig, animate_func, frames = len(ims), interval = 1000//4)\n\ndef load_dicom_line(path):\n t_paths = sorted(\n glob.glob(os.path.join(path, \"*\")), \n key=lambda x: int(x[:-4].split(\"-\")[-1]),\n )\n images = []\n for filename in t_paths:\n data = load_dicom(filename)\n if data.max() == 0:\n continue\n images.append(data)\n return images\n\ncreate_animation(load_dicom_line(\"../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00176/T2w\"))\n ","metadata":{"execution":{"iopub.status.busy":"2022-01-20T21:48:23.386828Z","iopub.execute_input":"2022-01-20T21:48:23.387156Z","iopub.status.idle":"2022-01-20T21:48:25.138332Z","shell.execute_reply.started":"2022-01-20T21:48:23.387123Z","shell.execute_reply":"2022-01-20T21:48:25.137138Z"},"trusted":true},"execution_count":10,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}
\ No newline at end of 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
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment