Guest User

Untitled

a guest
Nov 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import os
  4. import scipy.io as sio
  5.  
  6.  
  7. def write_files(mat_input_file, output_dir):
  8. if not os.path.exists(mat_input_file):
  9. raise Exception('Path does not exist: ' + mat_input_file)
  10.  
  11. if not os.path.exists(output_dir):
  12. os.mkdir(output_dir)
  13.  
  14. data = sio.loadmat(mat_input_file)
  15. counts = np.empty((data['X'].shape[3],)).astype(np.uint8)
  16.  
  17. for i in range(data['X'].shape[3]):
  18. truth = data['y'][i, 0]
  19.  
  20. if truth == 10:
  21. truth = 0
  22.  
  23. counts[i] = truth
  24. img = data['X'][..., i]
  25. cv2.imwrite(os.path.join(output_dir, str(i + 1) + '.png'), img)
  26.  
  27. np.savetxt(os.path.join(output_dir, 'labels.csv'), counts, delimiter=",", fmt='%d')
Add Comment
Please, Sign In to add comment