39 """A function that resizes a provided picture. 40 Inputs: width and height to resize to 42 Outputs: input_image_resized""" 44 if interpolation
is None:
45 if str(image.dtype).startswith((
"int",
"bool")):
46 interpolation = cv2.INTER_NEAREST
48 interpolation = cv2.INTER_LINEAR
50 image_resized = cv2.resize(image, dsize=(width, height), interpolation=interpolation)
55 """Resize And Crop to process and back""" 57 def __init__(self, hypes, original_image_size):
58 """A function that provides the indices to start and stop cropping the picture at. 59 Inputs: hypes file to get crop parameters, 61 Define: crop_y_from, crop_y_to, crop_x_from, crop_x_to, processing_image_size""" 64 """ Get field from h if such present, else return False""" 69 if 'jitter' in hypes.keys():
75 self.
resize_image = _get(h_,
'reseize_image')
or _get(h_,
'resize_image')
77 inter_image_size = (h_[
'image_width'], h_[
'image_height'])
79 inter_image_size = original_image_size[:2]
86 if 'crop_x_from' in h_.keys():
87 self.
crop_x_from = int(inter_image_size[0] * h_[
'crop_x_from'])
91 if 'crop_x_to' in hypes[
'jitter'].keys():
92 self.
crop_x_to = int(inter_image_size[0] * h_[
'crop_x_to'])
96 if 'crop_y_from' in h_.keys():
97 self.
crop_y_from = int(inter_image_size[1] * h_[
'crop_y_from'])
101 if 'crop_y_to' in h_.keys():
102 self.
crop_y_to = int(inter_image_size[1] * h_[
'crop_y_to'])
104 self.
crop_y_to = int(inter_image_size[1])
113 """A function that does all of the image preprocessing 114 Inputs: image to process 115 image_uncropped empty image for postprocessing (allocated if is None) 116 Outputs: preprocessed image, image_uncropped""" 118 preprocessed_image = image
129 if image_uncropped
is None:
130 image_uncropped = np.zeros(
131 (preprocessed_image.shape[0], preprocessed_image.shape[1]))
135 return preprocessed_image, image_uncropped
138 output_image_uncropped,
139 resulting_image_for_shape,
141 """A function that does all of the image preprocessing for KittiSeg 142 Inputs: image to process 143 output_image_uncropped empty image for postprocessing 144 Outputs: way_prediction""" 149 image = output_image_uncropped
153 image =
resize_image(resulting_image_for_shape.shape[0], resulting_image_for_shape.shape[1], image)
157 if str(image.dtype).startswith(
"float"):
158 if filter_data
is None:
160 way_prediction = image > filter_data
161 elif str(image.dtype).startswith(
"int"):
162 way_prediction = image.copy()
163 elif str(image.dtype).startswith(
"bool"):
164 way_prediction = image.copy()
167 assert str(image.dtype).startswith((
"float",
"int",
"bool"))
168 return way_prediction