-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflip.py
86 lines (79 loc) · 3.23 KB
/
flip.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import numpy as np
import pydicom
import cv2
#ddsm is a list of file names
def flip(DDSM):
for i in DDSM:
ds = pydicom.dcmread(i)
list = i.split("_")
if list[len(list) - 1] == "1" or list[len(list) - 1] == "2":
if list[len(list) - 3] == "RIGHT":
"""
height = ds.pixel_array.shape[0]
width = ds.pixel_array.shape[1]
for x in range(0, width / 2): # Only process the half way
for y in range(0, height):
# swap pix and pix2
one = ds.pixel_array[y, x]
two = ds.pixel_array[y, width-1-x]
ds.pixel_array[y, x] = two
ds.pixel_array[y, width-1-x] = one
ds.PixelData = ds.pixel_array.tostring()
ds.save_as(i)
"""
pixel_arr = cv2.flip(ds.pixel_array, 1)
ds.PixelData = pixel_arr.tostring()
ds.save_as(i)
else:
if list[len(list) - 2] == "RIGHT":
"""
height = ds.pixel_array.shape[0]
width = ds.pixel_array.shape[1]
for x in range(0, width / 2): # Only process the half way
for y in range(0, height):
# swap pix and pix2
one = ds.pixel_array[y, x]
two = ds.pixel_array[y, width - 1 - x]
ds.pixel_array[y, x] = two
ds.pixel_array[y, width - 1 - x] = one
"""
pixel_arr = cv2.flip(ds.pixel_array, 1)
ds.PixelData = pixel_arr.tostring()
ds.save_as(i)
def flip_single(i):
ds = pydicom.dcmread(i)
list = i.split("_")
if list[len(list)-1] == "1" or list[len(list)-1] == "2":
if list[len(list)-3] == "RIGHT":
"""
height = ds.pixel_array.shape[0]
width = ds.pixel_array.shape[1]
for x in range(0, width / 2): # Only process the half way
for y in range(0, height):
# swap pix and pix2
one = ds.pixel_array[y, x]
two = ds.pixel_array[y, width-1-x]
ds.pixel_array[y, x] = two
ds.pixel_array[y, width-1-x] = one
ds.PixelData = ds.pixel_array.tostring()
ds.save_as(i)
"""
pixel_arr = cv2.flip(ds.pixel_array, 1)
ds.PixelData = pixel_arr.tostring()
ds.save_as(i)
else:
if list[len(list)-2] == "RIGHT":
"""
height = ds.pixel_array.shape[0]
width = ds.pixel_array.shape[1]
for x in range(0, width / 2): # Only process the half way
for y in range(0, height):
# swap pix and pix2
one = ds.pixel_array[y, x]
two = ds.pixel_array[y, width - 1 - x]
ds.pixel_array[y, x] = two
ds.pixel_array[y, width - 1 - x] = one
"""
pixel_arr = cv2.flip(ds.pixel_array, 1)
ds.PixelData = pixel_arr.tostring()
ds.save_as(i)