I am trying to implement a non-uniformity correction algorithm on infrared images. Basically I have a set of images of a black body, which is supposed to be at a very precise and homogeneous temperature. But due to camera hardware (sensor, optics...), the image you get is not homogeneous. I have images (640*512 pix) at different temperatures (around 10 images from 18°C to 30°C), and I need to correct the values of each pixel, to fit the mean value of the central area (supposed to be the correct value). So, for each pixel, I need to fit a polynomial function p(order 5): x=p(y) where x is the value of the pixel, and y is the mean value of the central area. For now I vectorized my images to avoid double looping, and loop over each pixel: import numpy as np interp_degree=5 nb_of_pixels=640*512 image =np.random.rand(640,512) mean_value=np.arange(18,28,1) a=image.flatten() DL=np.transpose([a for i in range(10)]) # I simplified up to this point for the example K=np.empty((nb_of_pixels,interp_degree+1)) for i in range(len(DL)): # loop over each pixels K=np.polyfit(DL,mean_value,interp_degree) # fitting DLC_NUC=np.polyval(K,DL) # eval the corrected value of the pixel for later use This loop take about 200 sec on my computer, and I would like to reduce this time. polyfit and polyval already use multiprocessing, so this is not a way. Is there ways to improve this? Continue reading...