Zo komen dus uiteindelijk de 10 minuten EEG recordings eruit te zien (zonder de balk uiteraard):
Dat moet resultaat geven! Het 20K prijzengeld is al bijna van mij :-)
Omdat er 16 elektroden in he hoofd van die arme patienten geprikt zitten (ze noemen het iEEG: intracranial EEG (iEEG) which involves electrodes positioned on the surface of the cerebral cortex !!!)
wil ik de resultaten samenvoegen in een 'tensor' met een dimensie dus van (x, 16, 30, 310) die als output dus een 0 of een 1 moeten genereren. Met onderstaande code lukt dit uiteindelijk. Per datagroep (3 patienten / train en test) heeft dit wel een lange doorlooptijd. Nu ja. Putertje werkt ook graag 's nachts. :-)
'''
execfile('/Users/DWW/Documents/_EEG/data.py')
'''
import os
import numpy as np
from scipy.io import loadmat
import matplotlib.pyplot as plt
import cv2
#data_path = '/Users/DWW/EEG recordings/'
data_path = '/Volumes/Slot 4 2tB/EEG recordings/'
work_path = '/Users/DWW/EEG recordings/'
image_rows = 480
image_cols = 620
def create_data(subdir, train=True):
train_data_path = os.path.join(data_path, subdir)
imagelist = os.listdir(train_data_path)
total = 16 * len(imagelist) # 16 electrodes
t = 0
print('-'*30)
print('Creating test images...')
print('-'*30)
images, imageset, outcome = [],[], []
for image_name in imagelist: #[0:3]:
if image_name[-4:] == '.mat':
try:
single_matdata = loadmat(os.path.join(train_data_path, image_name))
except ValueError:
print "File ", image_name, " is corrupted"
else:
data = single_matdata['dataStruct']['data'][0][0]
imageset = []
for i in range(data.shape[1]):
x = np.where(np.abs(data[:,0])>100)
y = data[x,i]
plt.plot(x[0],y[0])
plt.axis('off')
plt.set_cmap('hot')
ax = plt.gca()
ax.set_axis_off()
ax.autoscale(False)
extent = ax.get_window_extent().transformed(plt.gcf().dpi_scale_trans.inverted())
plt.savefig('figuur', bbox_inches=extent)
plt.clf()
img = cv2.imread('figuur.png', cv2.IMREAD_GRAYSCALE)
#img = cv2.resize(img,(155,120), interpolation = cv2.INTER_AREA)
img = cv2.resize(img,(310,30), interpolation = cv2.INTER_AREA)
imageset.append(img)
#print np.asarray(imageset).shape
if t % 100 == 0:
print('Done: {0}/{1} images'.format(t, total))
t += 1
'''
cv2.imshow('figuur',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
'''
images.append(imageset)
if train: # Traindata - not test
outcome.append(image_name[-5])
#print np.asarray(images).shape, image_name, image_name[-5]
print('Loading done.')
return images, outcome
if __name__ == '__main__':
sources = ['train_1']#, 'test_1', 'train_2', 'test_2', 'train_3', 'test_3']
for subdir in sources:
if subdir[0:4] == 'trai':
output = True
else:
output = False
print 'Processing ' + subdir + ' ...'
images, outcome = create_data(subdir, output)
np.save(work_path + 'images_' + subdir + '.npy', images)
np.save(work_path + 'outcome_' + subdir + '.npy', outcome)
print('Saving to .npy files done for ' + subdir + '.')
'''
print(')Showing example ... images[1][1] ...')
cv2.imshow('figuur',images[1][1])
cv2.waitKey(0)
cv2.destroyAllWindows()
'''
Geen opmerkingen:
Een reactie posten