Why are these two arrays exactly the same?

52 Views Asked by At

This is my code.

import sys, os
import numpy as np
import matplotlib.pyplot as plt
import PIL
from PIL import Image

im = Image.open('C:/research/1.jpg')
im_bicubic = Image.open('C:/research/1.jpg')
wei, hei = im.width, im.height

im = im.resize((wei,hei), 0)
im_bicubic = im_bicubic.resize((wei,hei), PIL.Image.BICUBIC)

im.save('C:/research/1ori.jpg')
im_bicubic.save('C:/research/1bic.jpg')

Original image saved to "im".

bicubic interpolated image has been saved to "im_bicubic".

And I saved it to any folder, but when I look at it, there is no difference between the two images.

I added this code for verification.

im_array=np.asarray(im)
im_bicubic_array=np.asarray(im_bicubic)

print(im_bicubic_array - im_array)

The result is an array with all zeros.

The two arrays are exactly the same.

Why is one the original and the one using the interpolation method the same?

pillow, bicubic, I used another, but it was the same too.

Why are the two images exactly the same?

Did I mistake the code so that bicubic did not work?

Thanks you.

1

There are 1 best solutions below

1
miindlek On

Since you are resizing to exactly the same shape, there is no need to interpolate. This is why both images are still the same.

Interpolation does only make sense, if you are resizing to another shape.