Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pickle
- IMAGE_WIDTH = 3
- IMAGE_HEIGHT = 3
- FILE_COUNT = 3
- def gen_sample(count, width, height):
- with open('data/raw_data.pickle', 'wb') as f:
- for i in range(count):
- data = np.arange(9, dtype=np.float64) + i * 10
- data = data.reshape(height, width)
- pickle.dump(data, f)
- print i, data
- def preprocess(count, height):
- outfiles = []
- for i in range(height):
- outfilename = 'data/row_%03d.dat' % i
- outfiles.append(open(outfilename, 'wb'))
- with open('data/raw_data.pickle', 'rb') as f:
- for i in range(count):
- data = pickle.load(f)
- for j in range(height):
- data[j].tofile(outfiles[j])
- for i in range(height):
- outfiles[i].close()
- def process(width, height):
- result_rows = []
- for i in range(height):
- outfilename = 'data/row_%03d.dat' % i
- data = np.fromfile(outfilename, dtype=np.float64).reshape(-1, width)
- median_row = np.median(data, axis=0)
- result_rows.append(median_row)
- print i, data
- return np.vstack(result_rows)
- gen_sample(FILE_COUNT, IMAGE_WIDTH, IMAGE_HEIGHT)
- preprocess(FILE_COUNT, IMAGE_HEIGHT)
- result = process(IMAGE_WIDTH, IMAGE_HEIGHT)
- print "Result", result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement