-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorientacao.py
63 lines (48 loc) · 2.02 KB
/
orientacao.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
responsavel por verificar a orientacao dos exames e tentar corrigir as imagens em orientações erradas
https://www.kaggle.com/code/davidbroberts/determining-dicom-image-order
'''
import os
import numpy as np
import pandas as pd
import pydicom
import matplotlib.pyplot as plt
# Get a list of images in a series
def get_series_list(directory, study, series):
series_list = []
for subdirs, dirs, files in os.walk(directory + '/' + study + "/" + series):
series_list = os.listdir(directory + '/' + study + '/' + series)
return series_list
# Convert the Image Orientation Patient tag cosine values into a text string of the plane.
# This represents the plane the image is 'closest to' .. it does not explain any obliqueness
def get_image_plane(loc):
row_x = round(loc[0])
row_y = round(loc[1])
row_z = round(loc[2])
col_x = round(loc[3])
col_y = round(loc[4])
col_z = round(loc[5])
if (row_x, row_y, col_x, col_y) == (1,0,0,0):
return "Coronal"
if (row_x, row_y, col_x, col_y) == (0,1,0,0):
return "Sagittal"
if (row_x, row_y, col_x, col_y) == (1,0,0,1):
return "Axial"
return "Unknown"
# folder_dcm = r"E:\PycharmProjects\pythonProject\exame\CQ500CT420\Unknown Study\CT 0.625mm"
directory = 'E:\PycharmProjects\pythonProject\exame\CQ500CT420'
study = 'Unknown Study'
series = 'CT 0.625mm'
files = []
# Get a list of images for this study/series
series_list = get_series_list(directory, study, series)
if len(series_list) > 0:
for f in series_list:
# Read the image and get it's orientation and position tags
image = pydicom.dcmread(f'{directory}/{study}/{series}/{f}')
plane = get_image_plane(image[0x0020, 0x0037])
# Make a list
files.append([f, plane, float(image[0x0020, 0x0032].value[0]), float(image[0x0020, 0x0032].value[1]),float(image[0x0020, 0x0032].value[2])])
# Convert the list of files and position coords to a dataframe
df = pd.DataFrame(data=files, columns=('image','plane','iop_x','iop_y','iop_z'))
df.head(10)