Skip to content

Commit

Permalink
analyzin pixel spacings and pickled dict with pixel spaces and pids a…
Browse files Browse the repository at this point in the history
…s key
  • Loading branch information
EliasVansteenkiste committed Apr 5, 2017
1 parent cc08953 commit d981056
Show file tree
Hide file tree
Showing 3 changed files with 19,231 additions and 0 deletions.
45 changes: 45 additions & 0 deletions analyze_dsb_pixel_spacings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import cPickle as pickle
import string
import sys
import time
from itertools import izip
import numpy as np
from datetime import datetime, timedelta
import utils
import utils_lung
import logger
import buffering
import pathfinder
import data_iterators


candidates_config = 'dsb_c3_s5_p8a1'
predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH)
candidates_path = predictions_dir + '/%s' % candidates_config
id2candidates_path = utils_lung.get_candidates_paths(candidates_path)

train_valid_ids = utils.load_pkl(pathfinder.VALIDATION_SPLIT_PATH)
train_pids, valid_pids, test_pids = train_valid_ids['training'], train_valid_ids['validation'], train_valid_ids['test']
all_pids = train_pids + valid_pids + test_pids

data_iterator = data_iterators.DSBPixelSpacingsGenerator(pathfinder.DATA_PATH, id2candidates_path, all_pids)


z = []
y = []
x = []
pixel_spacings = {}

# use buffering.buffered_gen_threaded()
for idx, (pid, pixel_spacing) in enumerate(data_iterator.generate()):
print idx, pid, pixel_spacing
z.append(pixel_spacing[0])
y.append(pixel_spacing[1])
x.append(pixel_spacing[2])
pixel_spacings[pid] = pixel_spacing


utils.save_pkl(pixel_spacings, 'pixel_spacings_dsb.pkl')
print 'z', min(z), max(z)
print 'y', min(y), max(y)
print 'x', min(x), max(x)
29 changes: 29 additions & 0 deletions data_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,35 @@ def generate(self):
yield x_batch, y_batch, pid




class DSBPixelSpacingsGenerator(object):
def __init__(self, data_path, id2candidates_path, patient_ids):

self.id2candidates_path = id2candidates_path
self.patient_paths = []
if patient_ids is not None:
for pid in patient_ids:
if pid in self.id2candidates_path: # TODO: this should be redundant if fpr and segemntation are correctly generated
self.patient_paths.append(data_path + '/' + pid)
else:
raise ValueError('provide patient ids')

self.nsamples = len(self.patient_paths)
self.data_path = data_path

def generate(self):

for idx in xrange(self.nsamples):

patient_path = self.patient_paths[idx]
pid = utils_lung.extract_pid_dir(patient_path)

img, pixel_spacing = utils_lung.read_dicom_scan(patient_path)

yield pid, pixel_spacing


class DSBPatientsDataGenerator_only_heatmap(object):
def __init__(self, data_path, batch_size, transform_params, id2candidates_path, data_prep_fun,
n_candidates_per_patient, rng, random, infinite, candidates_prep_fun, return_patch_locs=False, shuffle_top_n=False, patient_ids=None):
Expand Down
Loading

0 comments on commit d981056

Please sign in to comment.