Commit cdb08a2e authored by Alessia Marcolini's avatar Alessia Marcolini
Browse files

Remove unused files

parent 0bd7b229
# IPython line magic to enable import and executions of `utils` in notebooks
# To enable this magic, please copy or link this file in your **startup** IPython folder
# Default Path: $HOME/.ipython/profile_default/startup
from IPython.core.magic import register_line_magic
from IPython.display import HTML as html_print
import os
import sys
def HN_env(line):
def set_path(path):
if not path:
path = '..'
curpath = os.path.abspath(os.path.curdir)
env = os.path.join(curpath, path)
sys.path += [env]
return f'<text style="color: green;">Success</text>'
return html_print(set_path(line))
preprocess.ipynb, Andrea, 10 Dec 2018
['HN-CHUM-005', 'HN-HMR-017', 'HN-HMR-007']
Errors in SUV conversion
\ No newline at end of file
%% Cell type:code id: tags:
``` python
#PATH = '/home/bizzego/UniTn/networks_dami'
PATH = '/media/damiana/DATA'
#PATH = '/media/damiana/Maxtor'
%% Cell type:code id: tags:
``` python
import os
import numpy as np
import SimpleITK as sitk
import pandas as pd
import dicom_utils.dicom_utils as du
import dicom_utils.dicom_utils.visualize as viz
import gc
def to_numpy(image):
%% Cell type:code id: tags:
``` python
DATADIR = f'{PATH}/data/original' #Original data
OUTDIR = f'{PATH}/data/processed/bbox_fixed2/' #Destinatino of processed data (a folder for each patient will be created)
DIR_INFO_FILE = f'{PATH}/data/summary.csv' #where to find the info about the Original data folders to use
ROI_INFO_FILE = f'{PATH}/data/INFO_GTVcontours_HN.csv' # where to find the info about the name of the ROI
%% Cell type:code id: tags:
``` python
BOX_SIZE = 128 #mm == pixels for voxel size of 1mm3
VOXEL_SIZE = [1,1,1]
gaussian = sitk.SmoothingRecursiveGaussianImageFilter()
dir_info = pd.read_csv(DIR_INFO_FILE)
roi_info = pd.read_csv(ROI_INFO_FILE)
subjects = os.listdir(DATADIR)
errors = []
%% Cell type:code id: tags:
``` python
SUB = subjects[:4]
%% Cell type:code id: tags:
``` python
for SUB in subjects[:4]: #cambiare
%% Output
%% Cell type:code id: tags:
``` python
%% Output
%% Cell type:code id: tags:
``` python
dir_info_sub = dir_info.query("subject == @SUB")
roi_name = roi_info.query('patient == @SUB')['roi_name'].values[0]
dir_CT = dir_info_sub.query("modality == 'CT'").dir.values[0]
dir_PT = dir_info_sub.query("modality == 'PT'").dir.values[0]
dir_RT = dir_info_sub.query("modality == 'RTSTRUCT'").dir.values[0]
scan_CT = du.load_series(os.path.join(DATADIR, dir_CT))
scan_PT = du.load_SUV(os.path.join(DATADIR, dir_PT))
if 'PETPET' in dir_RT:
segmentation = du.load_roi(os.path.join(DATADIR, dir_RT, '000000.dcm'), roi_name, scan_PT)
segmentation = du.load_roi(os.path.join(DATADIR, dir_RT, '000000.dcm'), roi_name, scan_CT)
start_mm, stop_mm = du.get_bbox_vertices(segmentation)
center_mm = (np.array(stop_mm) + np.array(start_mm))/2
start_mm = center_mm - HALF_BOX - 5 #add margin to allow a better interpolation
stop_mm = center_mm + HALF_BOX + 5
scan_CT_box = du.extract_volume(scan_CT, start_mm, stop_mm)
#upsample and register
scan_CT_box = du.processing.resample(scan_CT_box, spacing=VOXEL_SIZE)
scan_PT_box = sitk.Resample(scan_PT, scan_CT_box)
#segmentation_box = sitk.Resample(segmentation, scan_CT_box)
#segmentation_box = gaussian.Execute(segmentation_box)
#out = segmentation_box>0.5
start_mm = start_mm + 5 #remove margin
stop_mm = stop_mm - 5 #remove margin
scan_CT_box = du.extract_volume(scan_CT_box, start_mm, stop_mm)
scan_PT_box = du.extract_volume(scan_PT_box, start_mm, stop_mm)
out = np.stack([to_numpy(scan_CT_box), to_numpy(scan_PT_box)], axis = 0)#, to_numpy(segmentation_box)], axis = 0)
#save'{OUTDIR}/{SUB}.npy', out)
del scan_CT_box, scan_PT_box, segmentation, out
%% Output
%% Cell type:code id: tags:
``` python
print(f'Error processing sub: {SUB}')
%% Output
Error processing sub: HN-CHUM-001
['HN-CHUM-001', 'HN-CHUM-002', 'HN-CHUM-003', 'HN-CHUM-001', 'HN-CHUM-001']
%% Cell type:code id: tags:
``` python