PIL Image resize without interpolation

Viewed 74

The function below takes in a square numpy matrix (3x3 in the example), converts it to unit8 and then resizes it to be viewable on the TK canvas. The issue being that Image.resize() method resamples the image to smooth the pixelation. This is unwanted in my situation. https://pillow.readthedocs.io/en/stable/reference/Image.html States that the method has a resample parameter that defaults to bicubic and can be set to None. This does not seem to work however.

    def addKernel(self, kernel, index):
        imin = kernel.min()
        imax = kernel.max()
        a = (255 - 0) / (imax - imin)
        b = 255 - a * imax
        kernel = (a * kernel + b).astype(np.uint8)
        img = Image.fromarray(kernel)
        img=img.resize((80, 80), resample=None)
        photo_img = ImageTk.PhotoImage(image=img)
        self.kernelArray[index[0]][index[1]] = photo_img;

The resulting image is shown below followed by the expected image representative of the numpy array passed in. Is there any simple way to do this?

enter image description hereenter image description here

0 Answers
Related