-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhcp_nparray_2_png.py
50 lines (37 loc) · 1.5 KB
/
hcp_nparray_2_png.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 6 15:57:55 2019
@author: jeffreydurieux
email: [email protected]
Warning! change absolute paths
need to make a folder with <absolutpath>/pngimages
all subfolders in pngimages are made on the fly
"""
import os
import numpy as np
import imageio
def run_create_png(subjectrange):
'''
function for creating png images based on subjectrange (max = 1112)
'''
for subject in range(2):
os.chdir('/home/ubuntu/data/hcp_npy_data/')
datasubject = np.load('hcp_data_{}.npy'.format(subject))
datasubject = datasubject[0]
os.chdir('/home/ubuntu/data/hcp_pngimages/')
os.makedirs('subject{}'.format(subject))
os.chdir('subject{}'.format(subject))
idxim = np.shape(datasubject)
os.makedirs('axis0')
os.makedirs('axis1')
os.makedirs('axis2')
for ax0 in range(idxim[0]):
os.chdir('/home/ubuntu/data/hcp_pngimages/subject{}/axis0/'.format(subject))
imageio.imwrite('{}.png'.format(ax0), datasubject[ax0, :, :])
for ax1 in range(idxim[1]):
os.chdir('/home/ubuntu/data/hcp_pngimages/subject{}/axis1/'.format(subject))
imageio.imwrite('{}.png'.format(ax1), datasubject[:, ax1, :])
for ax2 in range(idxim[2]):
os.chdir('/home/ubuntu/data/hcp_pngimages/subject{}/axis2/'.format(subject))
imageio.imwrite('{}.png'.format(ax2), datasubject[:, :, ax2])