2

I have two images (aerial photographs):

  • ImageA is 4740x4240 and cell size is 0.1 m

  • ImageB is 1849x1653 and cell size is 0.25 m.

I want ImageB with the same size than ImageA. I used the following code to generate the new image:

import gdal
import cv2
from PIL import Image

## Input
imageA = cv2.imread(r"\\imageA.tif", -1)
imageB= cv2.imread(r"\\imageB.tif", -1)

## Output
output = r"\\imageC.tif"

## ImageA dimensions
x = imageA.shape[1]
y = imageA.shape[0]

## Resizing imageB
imageC = cv2.resize(src = imageB, dsize = (x, y), interpolation = cv2.INTER_NEAREST)
imageC = Image.fromarray(imageC).convert('L')
imageC.save(output)

As expected, the new image is 4740x4240 with a cell size of 0.1 m. But I get wrong values for left and right borders (value 255) as you can see below (for the right border). How could I resolve it and obtain interpolated values?

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.