AddCloudMaskTask updated resizing
@@ -9,7 +9,7 @@ import scipy.ndimage
from sentinelhub import WmsRequest, WcsRequest, DataSource, CustomUrlParam, MimeType, ServiceType
from s2cloudless import S2PixelCloudDetector, MODEL_EVALSCRIPT
-from eolearn.core import EOTask, get_common_timestamps
+from eolearn.core import EOTask, get_common_timestamps, resize_images
INTERP_METHODS = ['nearest', 'linear']
@@ -159,12 +159,10 @@ class AddCloudMaskTask(EOTask):
# Rescaling factor in spatial (height, width) dimensions
rescale = self._get_rescale_factors(hr_array.shape[1:3], meta_info)
- if smooth:
- sigma = (0,) + tuple(int(1/x) for x in rescale) + (0,)
- hr_array = scipy.ndimage.gaussian_filter(hr_array, sigma)
-
- lr_array = scipy.ndimage.interpolation.zoom(hr_array, (1.0,) + rescale + (1.0,),
- order=INTERP_METHODS.index(interp), mode='nearest')
+ lr_array = resize_images(hr_array,
+ scale_factors=rescale,
+ anti_alias=smooth,
+ interpolation=interp)
return lr_array, rescale
@@ -185,16 +183,11 @@ class AddCloudMaskTask(EOTask):
if rescale is None:
return lr_array.reshape(lr_shape)
- out_array = scipy.ndimage.interpolation.zoom(lr_array.reshape(lr_shape),
- (1.0,) + tuple(1 / x for x in rescale) + (1.0,),
- output=lr_array.dtype, order=INTERP_METHODS.index(interp),
- mode='nearest')
-
- # Padding and cropping might be needed to get to the reference shape
- out_shape = out_array.shape
- padding = tuple((0, np.max((h-o, 0))) for h, o in zip(hr_shape, out_shape))
- hr_array = np.pad(out_array, padding, 'edge')
- hr_array = hr_array[:, :hr_shape[1], :hr_shape[2], :]
+ # Resize to reference shape
+ output_size = reference_shape[1:]
+ hr_array = resize_images(lr_array.reshape(lr_shape),
+ new_size=output_size,
+ interpolation=interp)
return hr_array
