0

I'm trying to resize an NDVI image (derived by Sentinel 2 bands) with different methods in Python, but I always get an image whose values are 0.

I want that my image's dimensions are divisible by 5.

Here is my original image.

NDVI original image

I tried different methods, for example using cv2:

new_size = np.asarray(image1.shape) /5
new_size = new_size.astype(int) *5
image1 = cv2.resize(image1.astype('float32'), (new_size[0],new_size[1]))

And this is the result

Resized image

Other methods (pillow, gdal, rasterio) return the same result. Does anyone know how to correctly resize the image?

1 Answers1

0

We need to convert image1 to a numpy array in order to get its shape, apply astype(), etc.:

new_size = np.asarray(np.array(image1).shape) /5
new_size = new_size.astype(int) *5
image1 = cv2.resize(np.array(image1).astype('float32'), (new_size[0],new_size[1]))

To display the image1 array as RGBA:

import matplotlib.pyplot as plt
image1 = image1 / 255.0
plt.imshow(image1)

or just RGB:

import matplotlib.pyplot as plt
image1 = image1[:, :, :-1] / 255.0
plt.imshow(image1)
Ori Yarden PhD
  • 1,287
  • 1
  • 4
  • 8