Skip to content

Commit

Permalink
generating histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasVansteenkiste committed Apr 7, 2017
1 parent 73b00e5 commit 7c0ad91
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
46 changes: 46 additions & 0 deletions generate_dsb_histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 logger
import buffering
from configuration import config, set_configuration
import pathfinder
import utils_plots
import data_iterators
import data_transforms

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt


predictions_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
outputs_path = predictions_dir + 'dsb_scan_histograms'
utils.auto_make_dir(outputs_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']
print 'n train', len(train_pids)
print 'n valid', len(valid_pids)
print 'n test', len(test_pids)

all_pids = train_pids + valid_pids + test_pids

data_iterator = data_iterators.DSBDataGenerator(data_path=pathfinder.DATA_PATH, patient_pids=all_pids)

histograms = {}
bins = np.arange(-960,1700,40)
# avg_histogram = np.zeros((bins.shape[0]-1), dtype=np.int64)
# use buffering.buffered_gen_threaded()
for idx, (x, pid) in enumerate(data_iterator.generate()):
print idx, 'pid', pid
histograms[pid]= data_transforms.get_rescale_params_hist_eq(x)



pickle.dump(histograms, open( "dsb_rescale_params_hist_eq.pkl", "wb" ) )
52 changes: 52 additions & 0 deletions generate_luna_histograms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 logger
import buffering
from configuration import config, set_configuration
import pathfinder
import utils_plots
import data_iterators
import data_transforms

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt



train_valid_ids = utils.load_pkl(pathfinder.LUNA_VALIDATION_SPLIT_PATH)
train_pids, valid_pids = train_valid_ids['train'], train_valid_ids['valid']

all_pids = train_pids + valid_pids

data_iterator = data_iterators.LunaSimpleDataGenerator(data_path=pathfinder.LUNA_DATA_PATH, patient_ids=all_pids)

histograms = {}
# bins = np.arange(-960,1700,40)
# avg_histogram = np.zeros((bins.shape[0]-1), dtype=np.int64)
# use buffering.buffered_gen_threaded()
for idx, (x, pid) in enumerate(data_iterator.generate()):
print idx, 'pid', pid
# if (idx == 10):
# break
histograms[pid]= data_transforms.get_rescale_params_hist_eq(x)


#plot avg histogram
# width = 0.7 * (bins[1] - bins[0])
# center = (bins[:-1] + bins[1:]) / 2
# plt.bar(center, avg_histogram, align='center', width=width)
# plt.savefig('dsb_histogram_avg.jpg')
# plt.clf()


pickle.dump(histograms, open( "luna_rescale_params_hist_eq.pkl", "wb" ) )



0 comments on commit 7c0ad91

Please sign in to comment.