Skip to content
Advertisement

How to upscale an image so that the result is not blurry or black?

I’m using the following code in order to upscale an image.

import matplotlib.pyplot as plt
import numpy as np
from skimage.transform import rescale, resize

image = np.array(
    [[[51, 153, 255],
      [224, 224, 224],
      [224, 224, 224],
      [224, 224, 224]],

     [[224, 224, 224],
      [224, 224, 224],
      [224, 224, 224],
      [224, 224, 224]],

     [[224, 224, 224],
      [224, 224, 224],
      [224, 224, 224],
      [224, 224, 224]],

     [[224, 224, 224],
      [224, 224, 224],
      [224, 224, 224],
      [51, 255, 51]]]
)

# image2 = rescale(image, 40.0, anti_aliasing=True, multichannel=True).astype(np.int) # produces a black image
image2 = rescale(image, 40.0, anti_aliasing=True, multichannel=True) # produces a black image
# image2 = resize(image, (255, 255, 3)) # produces a black image

print(image2)

plt.imshow(image)
plt.show()

plt.imshow(image2)
plt.show()

However, this is not working as expected, as image2 becomes black. I really want to produce a new array, because I will be saving this array as an image to the file system. Specifically, I will create a gif animation from the upscaled version of these arrays. However, I want to create an upscaled version that is not blurry, but like the original, as you can see when you imshow(image) above, i.e.

enter image description here

I guess I am using the API incorrectly and, meanwhile, maybe I will figure out the right way of doing what I want.

Advertisement

Answer

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement