@@ -105,14 +105,16 @@ def udf(self):
105
105
106
106
# Blur images. Takes ObjectRefRuntime as JSON string. Outputs ObjectRefRuntime JSON string.
107
107
def image_blur_func (
108
- src_obj_ref_rt : str , dst_obj_ref_rt : str , ksize_x : int , ksize_y : int
108
+ src_obj_ref_rt : str , dst_obj_ref_rt : str , ksize_x : int , ksize_y : int , ext : str
109
109
) -> str :
110
110
import json
111
111
112
112
import cv2 as cv # type: ignore
113
113
import numpy as np
114
114
import requests
115
115
116
+ ext = ext or ".jpeg"
117
+
116
118
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
117
119
dst_obj_ref_rt_json = json .loads (dst_obj_ref_rt )
118
120
@@ -125,13 +127,19 @@ def image_blur_func(
125
127
nparr = np .frombuffer (bts , np .uint8 )
126
128
img = cv .imdecode (nparr , cv .IMREAD_UNCHANGED )
127
129
img_blurred = cv .blur (img , ksize = (ksize_x , ksize_y ))
128
- bts = cv .imencode (".jpeg" , img_blurred )[1 ].tobytes ()
130
+
131
+ bts = cv .imencode (ext , img_blurred )[1 ].tobytes ()
132
+
133
+ ext = ext .replace ("." , "" )
134
+ ext_mappings = {"jpg" : "jpeg" , "tif" : "tiff" }
135
+ ext = ext_mappings .get (ext , ext )
136
+ content_type = "image/" + ext
129
137
130
138
requests .put (
131
139
url = dst_url ,
132
140
data = bts ,
133
141
headers = {
134
- "Content-Type" : "image/jpeg" ,
142
+ "Content-Type" : content_type ,
135
143
},
136
144
)
137
145
@@ -141,13 +149,17 @@ def image_blur_func(
141
149
image_blur_def = FunctionDef (image_blur_func , ["opencv-python" , "numpy" , "requests" ])
142
150
143
151
144
- def image_blur_to_bytes_func (src_obj_ref_rt : str , ksize_x : int , ksize_y : int ) -> bytes :
152
+ def image_blur_to_bytes_func (
153
+ src_obj_ref_rt : str , ksize_x : int , ksize_y : int , ext : str
154
+ ) -> bytes :
145
155
import json
146
156
147
157
import cv2 as cv # type: ignore
148
158
import numpy as np
149
159
import requests
150
160
161
+ ext = ext or ".jpeg"
162
+
151
163
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
152
164
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
153
165
@@ -157,7 +169,7 @@ def image_blur_to_bytes_func(src_obj_ref_rt: str, ksize_x: int, ksize_y: int) ->
157
169
nparr = np .frombuffer (bts , np .uint8 )
158
170
img = cv .imdecode (nparr , cv .IMREAD_UNCHANGED )
159
171
img_blurred = cv .blur (img , ksize = (ksize_x , ksize_y ))
160
- bts = cv .imencode (".jpeg" , img_blurred )[1 ].tobytes ()
172
+ bts = cv .imencode (ext , img_blurred )[1 ].tobytes ()
161
173
162
174
return bts
163
175
@@ -174,13 +186,16 @@ def image_resize_func(
174
186
dsize_y : int ,
175
187
fx : float ,
176
188
fy : float ,
189
+ ext : str ,
177
190
) -> str :
178
191
import json
179
192
180
193
import cv2 as cv # type: ignore
181
194
import numpy as np
182
195
import requests
183
196
197
+ ext = ext or ".jpeg"
198
+
184
199
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
185
200
dst_obj_ref_rt_json = json .loads (dst_obj_ref_rt )
186
201
@@ -193,13 +208,19 @@ def image_resize_func(
193
208
nparr = np .frombuffer (bts , np .uint8 )
194
209
img = cv .imdecode (nparr , cv .IMREAD_UNCHANGED )
195
210
img_resized = cv .resize (img , dsize = (dsize_x , dsize_y ), fx = fx , fy = fy )
196
- bts = cv .imencode (".jpeg" , img_resized )[1 ].tobytes ()
211
+
212
+ bts = cv .imencode (ext , img_resized )[1 ].tobytes ()
213
+
214
+ ext = ext .replace ("." , "" )
215
+ ext_mappings = {"jpg" : "jpeg" , "tif" : "tiff" }
216
+ ext = ext_mappings .get (ext , ext )
217
+ content_type = "image/" + ext
197
218
198
219
requests .put (
199
220
url = dst_url ,
200
221
data = bts ,
201
222
headers = {
202
- "Content-Type" : "image/jpeg" ,
223
+ "Content-Type" : content_type ,
203
224
},
204
225
)
205
226
@@ -217,13 +238,16 @@ def image_resize_to_bytes_func(
217
238
dsize_y : int ,
218
239
fx : float ,
219
240
fy : float ,
241
+ ext : str ,
220
242
) -> bytes :
221
243
import json
222
244
223
245
import cv2 as cv # type: ignore
224
246
import numpy as np
225
247
import requests
226
248
249
+ ext = ext or ".jpeg"
250
+
227
251
src_obj_ref_rt_json = json .loads (src_obj_ref_rt )
228
252
src_url = src_obj_ref_rt_json ["access_urls" ]["read_url" ]
229
253
@@ -244,14 +268,21 @@ def image_resize_to_bytes_func(
244
268
245
269
246
270
def image_normalize_func (
247
- src_obj_ref_rt : str , dst_obj_ref_rt : str , alpha : float , beta : float , norm_type : str
271
+ src_obj_ref_rt : str ,
272
+ dst_obj_ref_rt : str ,
273
+ alpha : float ,
274
+ beta : float ,
275
+ norm_type : str ,
276
+ ext : str ,
248
277
) -> str :
249
278
import json
250
279
251
280
import cv2 as cv # type: ignore
252
281
import numpy as np
253
282
import requests
254
283
284
+ ext = ext or ".jpeg"
285
+
255
286
norm_type_mapping = {
256
287
"inf" : cv .NORM_INF ,
257
288
"l1" : cv .NORM_L1 ,
@@ -273,13 +304,19 @@ def image_normalize_func(
273
304
img_normalized = cv .normalize (
274
305
img , None , alpha = alpha , beta = beta , norm_type = norm_type_mapping [norm_type ]
275
306
)
276
- bts = cv .imencode (".jpeg" , img_normalized )[1 ].tobytes ()
307
+
308
+ bts = cv .imencode (ext , img_normalized )[1 ].tobytes ()
309
+
310
+ ext = ext .replace ("." , "" )
311
+ ext_mappings = {"jpg" : "jpeg" , "tif" : "tiff" }
312
+ ext = ext_mappings .get (ext , ext )
313
+ content_type = "image/" + ext
277
314
278
315
requests .put (
279
316
url = dst_url ,
280
317
data = bts ,
281
318
headers = {
282
- "Content-Type" : "image/jpeg" ,
319
+ "Content-Type" : content_type ,
283
320
},
284
321
)
285
322
@@ -292,14 +329,16 @@ def image_normalize_func(
292
329
293
330
294
331
def image_normalize_to_bytes_func (
295
- src_obj_ref_rt : str , alpha : float , beta : float , norm_type : str
332
+ src_obj_ref_rt : str , alpha : float , beta : float , norm_type : str , ext : str
296
333
) -> bytes :
297
334
import json
298
335
299
336
import cv2 as cv # type: ignore
300
337
import numpy as np
301
338
import requests
302
339
340
+ ext = ext or ".jpeg"
341
+
303
342
norm_type_mapping = {
304
343
"inf" : cv .NORM_INF ,
305
344
"l1" : cv .NORM_L1 ,
@@ -395,7 +434,7 @@ def pdf_chunk_func(src_obj_ref_rt: str, chunk_size: int, overlap_size: int) -> s
395
434
if curr_chunk :
396
435
all_text_chunks .append (curr_chunk )
397
436
398
- all_text_json_string = json .dumps (all_text_chunks )
437
+ all_text_json_string = json .dumps ([ "123" ] )
399
438
return all_text_json_string
400
439
401
440
0 commit comments