8
8
from skimage .measure import shannon_entropy
9
9
from skimage .metrics import normalized_mutual_information as _normalized_mutual_information
10
10
from skimage .metrics import structural_similarity as ssim
11
- from skimage .transform import downscale_local_mean as _downscale
12
11
from skimage .transform import resize
13
12
14
13
from boiling_learning .preprocessing .transformers import Operator
@@ -231,29 +230,6 @@ def downscale(
231
230
) -> _VideoFrameOrFrames :
232
231
# 4-D Tensor of shape [batch, height, width, channels] or 3-D Tensor of shape
233
232
# [height, width, channels].
234
-
235
- if isinstance (factors , int ):
236
- height_factor , width_factor = factors , factors
237
- else :
238
- height_factor , width_factor = factors
239
-
240
- CHANNEL_FACTOR = 1
241
- if image .ndim == 3 :
242
- downscale_factors = (height_factor , width_factor , CHANNEL_FACTOR )
243
- elif image .ndim == 4 :
244
- BATCH_FACTOR = 1
245
- downscale_factors = (BATCH_FACTOR , height_factor , width_factor , CHANNEL_FACTOR )
246
- else :
247
- raise RuntimeError (f'image must have either 3 or 4 dimensions, got { image .ndim } ' )
248
-
249
- return typing .cast (_VideoFrameOrFrames , _downscale (image , downscale_factors ))
250
-
251
-
252
- def _downscale_tf (
253
- image : _VideoFrameOrFrames , factors : Union [int , Tuple [int , int ]]
254
- ) -> _VideoFrameOrFrames :
255
- # 4-D Tensor of shape [batch, height, width, channels] or 3-D Tensor of shape
256
- # [height, width, channels].
257
233
if image .ndim == 3 :
258
234
height = image .shape [0 ]
259
235
width = image .shape [1 ]
@@ -263,17 +239,14 @@ def _downscale_tf(
263
239
else :
264
240
raise RuntimeError (f'image must have either 3 or 4 dimensions, got { image .ndim } ' )
265
241
266
- if isinstance (factors , int ):
267
- height_factor , width_factor = factors , factors
268
- else :
269
- height_factor , width_factor = factors
242
+ height_factor , width_factor = ( factors , factors ) if isinstance (factors , int ) else factors
243
+
244
+ new_height = round ( height / height_factor )
245
+ new_width = round ( width / width_factor )
270
246
271
247
return typing .cast (
272
248
_VideoFrameOrFrames ,
273
- tf .image .resize (
274
- image ,
275
- (height // height_factor , width // width_factor ),
276
- ).numpy (),
249
+ tf .image .resize (image , (new_height , new_width ), antialias = True ).numpy (),
277
250
)
278
251
279
252
0 commit comments