-1

I found a Python library "imread" in github that reads raster image with more than 3 band. But it only does that I was wondering is there other library that resize the image like how we can resize RGB with 3 band. I know GDAL does that but I am not good with GDAL in Python. How can I do this from GDAL or rasterio?

Example with opencv2

list=[]
r = cv2.imread("path")
r = cv2.resize(r,(shape to resize))
r.append(list)
1

1 Answer 1

1

You can use rasterio. This is the documentation: https://rasterio.readthedocs.io/en/latest/topics/resampling.html

import rasterio
from rasterio.enums import Resampling

with rasterio.open("example.tif") as dataset:

    # resample data to target shape
    data = dataset.read(
        out_shape=(
            dataset.count,
            new_height,
            new_width
        ),
        resampling=Resampling.bilinear #you can also use nearest or bicubic if you want
    )

    # scale image transform
    transform = dataset.transform * dataset.transform.scale(
        (dataset.width / data.shape[-1]),
        (dataset.height / data.shape[-2])
    )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.