%load_ext autoreload
%autoreload 2
import sys
sys.path.append("../")
from utils import *
# define paths
input_path = "COVID-19-AR/nifti_files/"
output_path = "COVID-19-AR/output_files/"
cropped_path = "COVID-19-AR/cropped_nifti_files/"
cropped_json_path = "COVID-19-AR/cropped_output_files/"
plot_volumes_interactive(input_path, start_index=36)
interactive(children=(BoundedFloatText(value=36.0, description='File:', max=190.0, step=1.0), Output()), _dom_…
from bpreg.scripts.bpreg_inference import bpreg_inference
# bpreg_inference(input_path, output_path, plot=True)
plot_scores_interactive(output_path, input_path, start_index=166)
interactive(children=(BoundedFloatText(value=166.0, description='File:', max=190.0, min=166.0, step=1.0), Outp…
df = create_meta_data_table(output_path)
# Filter CT scans with less than 20 slices
df = df[df.z > 20]
plot_dicomexamined_distribution(df,
others_percentage_upper_bound=0.015)
191it [00:00, 470.90it/s]
# Filter corrupted CT scans
df_cleaned = df[df['BODY PART'] != 'NONE']
print(f"Dataset size after removing {len(df) - len(df_cleaned)} corrupted CT scans: {len(df_cleaned)}")
Dataset size after removing 20 corrupted CT scans: 125
plot_dicomexamined_distribution(df_cleaned,
others_percentage_upper_bound=0.02)
# Removing CT scans where the chest is not examined
df_cleaned = df_cleaned[df_cleaned['BODY PART'].str.contains('CHEST')]
print(f"Dataset after removing CT scans, where the CHEST is not visible: {len(df_cleaned)}")
Dataset after removing CT scans, where the CHEST is not visible: 107
plot_dicomexamined_distribution(df_cleaned,
others_percentage_upper_bound=0.02)
import pandas as pd
json_filepaths = [output_path + f for f in os.listdir(output_path) if f.endswith(".json")]
x = load_json(json_filepaths[0])
lookuptable = pd.DataFrame(x["look-up table"]).T
lookuptable.sort_values(by="mean")[["mean"]]
mean | |
---|---|
pelvis_start | 0.000 |
femur_end | 13.616 |
L5 | 25.532 |
pelvis_end | 28.824 |
L4 | 29.414 |
L3 | 33.817 |
kidney | 37.597 |
L2 | 37.763 |
L1 | 41.478 |
lung_start | 44.143 |
Th12 | 44.952 |
Th11 | 47.725 |
Th10 | 51.069 |
Th9 | 53.994 |
liver_end | 54.479 |
Th8 | 56.856 |
Th7 | 59.851 |
Th6 | 63.177 |
Th5 | 65.964 |
Th4 | 68.499 |
Th3 | 70.973 |
Th2 | 73.401 |
lung_end | 75.389 |
Th1 | 75.794 |
C7 | 77.937 |
C6 | 79.497 |
C5 | 81.826 |
C4 | 83.817 |
C3 | 85.647 |
teeth | 86.908 |
C2 | 87.206 |
C1 | 89.234 |
nose | 92.567 |
eyes_end | 100.000 |
head_end | 107.756 |
nifti_filepaths = [input_path + f.replace(".json", ".nii.gz") for f in df_cleaned.FILE]
# crop and save ct images to chest region
# crop_ct_images(nifti_filepaths, output_path, cropped_path, save=True)
# create body part meta data for cropped images
# bpreg_inference(cropped_path, cropped_json_path, plot=True, gpu_available=False)
plot_volumes_interactive(cropped_path)
interactive(children=(BoundedFloatText(value=0.0, description='File:', max=108.0, step=1.0), Output()), _dom_c…