Image gradients become inaccurate when scaling using various methods

We have a rather complicated image processing script written in Python that uses PIL and numpy. For one of the stages, we have very sensitive multichannel gradients, which are a lookup table. Once it was created, it is saved up to several different lower resolutions. However, when this happens, the green channel, which has a gradient going left and right, suddenly becomes lost. It should lose 1 out of 255 values ​​every 50 pixels or so. Instead, it begins to decline with values ​​of 2 for every 100 pixels. This causes enormous problems, and I cannot understand why PIL does this. However, I see transitions 1 in other parts of the map, so I don’t think it’s easy, since its missing one bit of accuracy. I also noticed on another channel it seemedthat the whole card was shifted by 1 value. The whole thing seems inaccurate after scaling, even when using the "Nearest" filter.

For a full-sized image, we create it from our numpy array with the following:

image = Image.fromarray(imageIn.astype(np.uint8))

Then we scale it:

new_image = image.resize(new_size, scaleFilter)

The scale is always twice as large, and I tried all the available zoom options.

Then we save it in PNG as follows:

new_image.save(file_name, 'PNG')

We save both large and immediately after step 1 with the same save command, and this is normal. After the scale, we have a problem on the green channel. Any help would be great!

EDIT:

Now it seems like this is a problem in SciPy. The following problem still causes the problem:

    new_array = misc.imresize(imageIn, (x_size, y_size, 4), interp='nearest')
    misc.imsave(file_name,new_array)

I do not understand how I even get distortion with the closest. I allocate this array as float64, but it should include rounding issues in code

EDIT # 2:

OSX, , ! Adobe After Effects, . imagemagick, . , , .

β„– 3

, . , OSX, "", , Photoshop .

:

enter image description here

.

enter image description here

, , ,

EDIT # 4

OpenGL , , ! ?

+4
1

, 50%, skimage:

import numpy
import skimage
import skimage.io

img = skimage.io.imread('uY173.png')

import skimage.transform

img50_order0 = skimage.img_as_ubyte( skimage.transform.rescale(img, 0.5, order=0, clip=True) )
img50_order1 = skimage.img_as_ubyte( skimage.transform.rescale(img, 0.5, order=1, clip=True) )

img50_lm = numpy.rint( skimage.transform.downscale_local_mean(img, (2,2,1), clip=True) )

import scipy.ndimage.interpolation

img50_nd = scipy.ndimage.interpolation.zoom(img, (0.5, 0.5, 1))

# plot section of green channel along horizontal axis
plot(img50_order0[50, :, 1])
plot(img50_order1[50, :, 1])
plot(img50_lm[50, :, 1])
plot(img50_nd[50, :, 1])

( ) PIL . uint8, - , uint8. 1, - 2.

+2

All Articles