This repository has been archived by the owner on Jul 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
block2.py
41 lines (34 loc) · 1.53 KB
/
block2.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
#!/usr/bin/env python
from __future__ import print_function
import dicom
import os
import numpy as np
from scipy.ndimage import gaussian_filter
from hough_transform_new import hough
folder = '/home/rharish/Programs/Python/Fiducial/2012.09.15 ACRELIC2 CT Scan '\
'Data from ACTREC/09171420/'
images_axial = []
print("Importing DICOM...")
for dicom_img in sorted(os.listdir(folder), key=lambda img: int(img)):
dic = dicom.read_file(folder + dicom_img)
if 'AXIAL' in dic.ImageType:
images_axial.append(dic)
images_axial.append(dic)
print("Forming arrays...")
pixel_spacing = list(map(float, images_axial[0].PixelSpacing))
images_axial = np.array([np.uint8(np.where(dic.pixel_array > 255, 255,
dic.pixel_array)) for dic in sorted(images_axial,
key=lambda dic: int(dic.SliceLocation))])
images_sagittal = np.array(list(map(lambda img: gaussian_filter(img, 1),
np.swapaxes(np.swapaxes(images_axial, 0, 2), 1, 2)[:, ::-1, :])))
images_coronal = np.array(list(map(lambda img: gaussian_filter(img, 1),
np.swapaxes(images_axial, 0, 1)[:, ::-1, :])))
images_axial = np.array(list(map(lambda img: gaussian_filter(img, 1),
images_axial)))
if __name__ == '__main__':
print("Starting detection...")
xs, ys, zs = zip(*hough(images_axial, images_coronal, images_sagittal))
xs = np.int32(np.array(xs) * pixel_spacing[1])
ys = np.int32(np.array(ys) * pixel_spacing[0])
zs = np.int32(np.array(zs) * 512 * (pixel_spacing[0] / len(images_axial)))
print(list(zip(xs, ys, zs)))