Generate a nonuniform illumination (bias field) 2D image
I provide an example for the generation of a nonuniform illumination using polynomials.

First, I take a vertical lineout (see first image) out of your last image, X being the pixel position and Y being the image intensity. For the horizontal direction I am using a simple parabola. Using kroneker product, the image is generated.



In order to ensure that the image intensity is between 1-alpha and 1+alpha, a streching is implemented as proposed by @Carl_Witthoft.

See code and resulting image below:



N=3; % degree of polynomial fit
alpha=0.2;

c = polyfit(X,Y,N);

y_f = zeros(size(Y));

for i=0:N
    y_f = y_f + c(N-i+1)*X.^i;
end

figure;
plot(X,Y, 'DisplayName', 'lineout'); hold on;
plot(X,y_f, 'DisplayName', 'fit'); legend show;

y_f = y_f./100;

xr = linspace(-4,4,150);
yr = 2-0.1*xr.^2;

img = kron(yr,y_f);

%% ensure that all values are between 1-\alpha and 1+\alpha

minV = min(img(:));
maxV = max(img(:));
mV = maxV-minV;

img = img-minV;                 % now from 0 to maxV-minV
img = img/(maxV-minV)*2*alpha;  % now from 0 to 2*alpha
img = img + 1-alpha;            % now from 1-alpha to 1+alpha

figure; imshow(img,[])