10
10
11
11
12
12
13
- def process_Standard_pickedpdf (picked_files ,orig_radar_dir ,layer_save , cresis_flag = 1 , layer_save_type = 1 , layer_load = '' ):
13
+ def process_Standard_pickedpdf (picked_files ,orig_radar_dir ,layer_save , cresis_flag = 1 , layer_save_type = 1 , layer_load = '' , find_rows_from_fullimageset = 0 ):
14
14
"""
15
15
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected] )
16
16
%
@@ -26,6 +26,9 @@ def process_Standard_pickedpdf(picked_files,orig_radar_dir,layer_save, cresis_fl
26
26
% layer_save_type=1 - For most applications, this should be set to 1, which is, save files in your current dir.
27
27
% 0 - This allows you to save layer files within the cresis file_tree
28
28
% layer_load='' - This is not fully implemented, but it would allow you to populate existing layer files
29
+ % find_rows_from_fullimageset - Setting this to 1 will search all images to figure out which rows
30
+ % of pixels are within the plot. For use when some of the bottom of radargrams
31
+ % is all white.
29
32
%
30
33
%%%%%%%%%%%%%%%
31
34
% The outputs are:
@@ -37,6 +40,7 @@ def process_Standard_pickedpdf(picked_files,orig_radar_dir,layer_save, cresis_fl
37
40
import glob
38
41
import os
39
42
import numpy as np
43
+ import matplotlib .pyplot as plt
40
44
41
45
from PIL import Image
42
46
import cv2
@@ -100,6 +104,8 @@ def process_Standard_pickedpdf(picked_files,orig_radar_dir,layer_save, cresis_fl
100
104
os .makedirs (comb_deconstruct_dir )
101
105
if not os .path .isdir (save_dir ):
102
106
os .makedirs (save_dir )
107
+
108
+
103
109
##########################################################################################################
104
110
# Part 3 #################################################################################################
105
111
######## Here we define the objects that need to be populated with picks
@@ -116,6 +122,42 @@ def process_Standard_pickedpdf(picked_files,orig_radar_dir,layer_save, cresis_fl
116
122
##########################################################################################################
117
123
# Part 5 ##################################################################################################
118
124
print ('Starting the information extraction.' )
125
+
126
+
127
+
128
+ ########## For images that have white at the bottom, we first look through all images to figure out the appropriate
129
+ ########## row indecies to use.
130
+
131
+ if find_rows_from_fullimageset == 1 :
132
+ for ind1 ,frame_fn in enumerate (frame_list ):
133
+ im_handle = Image .open (frame_fn )
134
+ np_frame = np .array (im_handle )
135
+ np_frame_dims = np_frame .shape
136
+
137
+ #print('Frame number %0.2d' % ind1)
138
+ #print('np_frame shape: ',np_frame_dims)
139
+
140
+ ########## For PNGs with RGB+components, this works best
141
+ if np_frame_dims [2 ] == 4 :
142
+ if ind1 == 0 :
143
+ im_frame = np .array (np_frame [:,:,3 ] != 0 ).astype (float )
144
+ else :
145
+ im_frame = im_frame + np .array (np_frame [:,:,3 ] != 0 ).astype (float )
146
+ ########## For greyscale+transparent, this is what you need
147
+ elif np_frame_dims [2 ] == 2 :
148
+ if ind1 == 0 :
149
+ im_frame = np .array (np_frame [:,:,1 ] != 0 ).astype (float )
150
+ else :
151
+ im_frame = im_frame + np .array (np_frame [:,:,1 ] != 0 ).astype (float )
152
+
153
+ if 'im_frame' in locals ():
154
+ #plt.imshow(im_frame)
155
+ selected_rows = ndh .minmax (np .where (im_frame > 0 )[0 ])
156
+ #print(selected_rows)
157
+ else :
158
+ find_rows_from_fullimageset = 0
159
+ print ('Something went wrong with the full image-set. Defaulting to local row search.' )
160
+
119
161
########## Here we actually load the images and extract pixel coordinate information
120
162
error_frames = []
121
163
good_frames = []
@@ -137,8 +179,11 @@ def process_Standard_pickedpdf(picked_files,orig_radar_dir,layer_save, cresis_fl
137
179
original_height = height_index ['index' ][0 ]+ 100
138
180
elif crop == 'nocrop' :
139
181
original_height = len (frame_data ['Time' ])
140
-
141
- picks = ndh .find_pixelcoords (frame_fn ,original_width ,original_height ,im_pick_params = [[2 ,25 ,1 ,10 ,1 ]])
182
+
183
+ if find_rows_from_fullimageset == 0 :
184
+ picks = ndh .find_pixelcoords (frame_fn ,original_width ,original_height ,im_pick_params = [[2 ,25 ,1 ,10 ,1 ]])
185
+ else :
186
+ picks = ndh .find_pixelcoords (frame_fn ,original_width ,original_height ,im_pick_params = [[2 ,25 ,1 ,10 ,1 ]], predefined_row_inds = selected_rows )
142
187
143
188
144
189
0 commit comments