Skip to content

Instantly share code, notes, and snippets.

@jbvimort
Created July 25, 2017 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbvimort/f0267dbe9fd47853ce0ffa5dd81829ec to your computer and use it in GitHub Desktop.
Save jbvimort/f0267dbe9fd47853ce0ffa5dd81829ec to your computer and use it in GitHub Desktop.
import os
import csv
import re
dataDir = "/home/jean-baptiste/Documents/4Neighborhood/CSVfeatureMaps/"
with open('trainingData.csv', 'w') as csvWritefile:
fieldnames = ['ID', 'Energy', 'Entropy', 'Correlation', 'InverseDifferenceMoment','Inertia', 'ClusterShade',
'ClusterProminence', 'HarralickCorrelation','ShortRunEmphasis', 'LongRunEmpasis','GreyLevelNonUniformity',
'RunLengthNonUniformity','LowGreyLevelRunEmphasis', 'HighGreyLevelRunEmphasis',
'ShortRunLowGreyLevelEmphasis', 'ShortRunHighGreyLevelEmphasis','LongRunLowGreyLevelEmphasis', 'LongRunHighGreyLevelEmphasis']
writer = csv.DictWriter(csvWritefile, fieldnames=fieldnames)
writer.writeheader()
for fileName in os.listdir(dataDir):
with open(dataDir + fileName, 'rb') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter=',', quotechar='|')
for row in spamreader:
if(row['X'] == '15' and row['Y'] == '15' and row['Z'] == '15'):
row['ID'] = re.search("_(.+?)_FeatureMap.csv", fileName).group(1)
row.pop('', None)
row.pop('X', None)
row.pop('Y', None)
row.pop('Z', None)
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment