17
17
result_folder = 'results/plots/keypoints'
18
18
19
19
20
- def plot_keypoints (image , mode , patid , slice_num , slice_dim = 1 , spacing = 1.5 ):
20
+ def plot_keypoints (image , mode , patid , slice_num , slice_dim = 1 , spacing = 1.5 , crop_indices = None ):
21
21
pts , _ , _ , _ = load_points (os .path .join (POINT_DIR_TS , mode ), patid )
22
22
pts = (pts .T + 1 )/ 2 * np .flip (np .array (image .shape ))[None ]
23
23
24
- crop_indices = crop_to_lung_indices (image )
24
+ if crop_indices is None :
25
+ crop_indices = crop_to_lung_indices (image )
25
26
slice_num_cropped = slice_num - crop_indices [slice_dim ].start
26
27
image = image [crop_indices ]
27
28
index = [slice (None )] * slice_dim + [slice (slice_num_cropped , slice_num_cropped + 1 )]
@@ -37,7 +38,7 @@ def plot_keypoints(image, mode, patid, slice_num, slice_dim=1, spacing=1.5):
37
38
ax .set_axis_off ()
38
39
ax .imshow (img_slice , cmap = 'gray' )
39
40
ax .scatter (pts_slice [:, pts_index [0 ]], pts_slice [:, pts_index [1 ]], marker = '+' , s = 150 , c = 'orangered' , linewidths = 2 )
40
- save_fig (fig , result_folder , f'{ mode } _keypoints_s0070_slice { slice_num } ' , pdf = False )
41
+ save_fig (fig , result_folder , f'{ mode } _keypoints_ { patid } _slice { slice_num } ' , pdf = False )
41
42
42
43
43
44
def plot_all (patid = 's0070' ):
@@ -50,6 +51,31 @@ def plot_all(patid='s0070'):
50
51
plot_keypoints (img_window , mode , slice_num = 118 , patid = patid , slice_dim = 1 )
51
52
52
53
54
+ def plot_bad_example_enhancement ():
55
+ patid = 's1024'
56
+ slice_num = 287 # 316
57
+ ds = ImageDataset (IMG_DIR_TS )
58
+ img_index = ds .get_index (patid , 'fixed' )
59
+ enhanced = ds .get_enhanced_fissures (img_index )
60
+ enhanced = sitk .GetArrayFromImage (enhanced )
61
+ mask = resample_equal_spacing (ds .get_lung_mask (img_index ), use_nearest_neighbor = True )
62
+ mask = sitk .GetArrayFromImage (mask )
63
+ enhanced [mask == 0 ], _ = slice_image (enhanced , slice_num = slice_num , slice_dim = 1 ).max ()
64
+ crop_indices = (slice (15 , 200 ), slice (0 , enhanced .shape [1 ]), slice (130 , 400 ))
65
+ plot_keypoints (enhanced , 'enhancement' , slice_num = slice_num , patid = patid , slice_dim = 1 , crop_indices = crop_indices )
66
+
67
+ img = ds .get_image (img_index )
68
+ img = resample_equal_spacing (img )
69
+ img_window = fissure_window_level_and_mask (sitk .GetArrayFromImage (img ), mask , high = 0 )
70
+ img_crop = img_window [crop_indices ]
71
+ img_slice , _ = slice_image (img_crop , slice_num = slice_num , slice_dim = 1 )
72
+ fig = create_image_figure (img_window )
73
+ ax = fig .gca ()
74
+ ax .set_axis_off ()
75
+ ax .imshow (img_slice , cmap = 'gray' )
76
+ save_fig (fig , result_folder , f'{ patid } _slice{ slice_num } ' , pdf = False )
77
+
78
+
53
79
def plot_enhancement (patid = 's0070' ):
54
80
ds = ImageDataset (IMG_DIR_TS )
55
81
img_index = ds .get_index (patid , 'fixed' )
@@ -77,21 +103,21 @@ def plot_enhancement(patid='s0070'):
77
103
slice_num = 118
78
104
slice_num_cropped = slice_num - crop_indices [slice_dim ].start
79
105
80
- enhanced = slice_image (enhanced , slice_num_cropped , slice_dim )
106
+ enhanced , _ = slice_image (enhanced , slice_num_cropped , slice_dim )
81
107
fig = create_image_figure (enhanced )
82
108
ax = fig .gca ()
83
109
ax .set_axis_off ()
84
110
ax .imshow (enhanced )
85
111
save_fig (fig , result_folder , 'enhancement_result' , pdf = False )
86
112
87
- planeness = slice_image (planeness , slice_num_cropped , slice_dim )
113
+ planeness , _ = slice_image (planeness , slice_num_cropped , slice_dim )
88
114
fig = create_image_figure (planeness )
89
115
ax = fig .gca ()
90
116
ax .set_axis_off ()
91
117
ax .imshow (planeness )
92
118
save_fig (fig , result_folder , 'enhancement_planeness' , pdf = False )
93
119
94
- hu_weights = slice_image (hu_weights , slice_num_cropped , slice_dim )
120
+ hu_weights , _ = slice_image (hu_weights , slice_num_cropped , slice_dim )
95
121
fig = create_image_figure (hu_weights )
96
122
ax = fig .gca ()
97
123
ax .set_axis_off ()
@@ -102,4 +128,5 @@ def plot_enhancement(patid='s0070'):
102
128
if __name__ == '__main__' :
103
129
KP_MODES .remove ('noisy' )
104
130
# plot_all()
105
- plot_enhancement ()
131
+ # plot_enhancement()
132
+ plot_bad_example_enhancement ()
0 commit comments