-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmat.py
41 lines (32 loc) · 912 Bytes
/
readmat.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
"""
@Description :
@Author : Xubo Luo
@Time : 2023/03/13 17:04:45
"""
import os
import scipy.io as scio
import pydicom
import numpy as np
matpath = './radonmethod/'
dcmpath = './weiying/'
savepath = './radon/'
dcmnames = os.listdir(dcmpath)
matnames = os.listdir(matpath)
cnt = 0
for (matname, dcmname) in zip(matnames, dcmnames):
print('Processing : ', cnt)
cnt += 1
dcm = pydicom.read_file(dcmpath + str(dcmname))
mat = scio.loadmat(matpath + str(matname))
data = mat['data']
# data[data>=3000] = 1024
pixel = data[0:512, 0:512] + 500
if dcm[0x0028, 0x0100].value == 16:
pixel = pixel.astype(np.uint16)
else:
pixel = pixel.astype(np.uint8)
# dcm.image = pixel
img = np.int16(pixel)
img = img.tobytes()
dcm.PixelData = img
dcm.save_as(savepath + str(dcmname) + '.dcm')