For an assignment I want to resize a .jpg image with a python code, but without using the pil.image.resize() function or another similar function. I want to write the code myself but I can't figure out how. The image is RGB. I have found this can be solved by nearest neighbor interpolation (as well as other methods but this one is fine for my specific assignment). The height and the width should both be able to be made bigger or smaller. So far I only have this:
import numpy as np
import scipy as sc
import matplotlib as plt
import math
import PIL
from PIL import Imageimg = np.array(Image.open("foto1.jpg")) height = img.shape[0]
width = img.shape[1]
dim = img.shape[2] new_h = int(input("New height: "))
new_w = int(input("New width: ")) imgR = img[:,:,0] #red pixels
imgG = img[:,:,1] #green pixels
imgB = img[:,:,2] #blue pixelsnewR = np.empty([new_h, new_w])
newG = np.empty([new_h, new_w])
newB = np.empty([new_h, new_w])
So now all three colours have a new array of the right dimensions. Unfortunately on the web I can only find people who use resize() functions... Does anyone know?
Thank in advance!