If I understand your question correctly you would like to generate images with non-uniform background illumination in order to test thresholding algorithms.
You could try to find a test set of images which already have a non-uniformly illuminated background. For example, rice.png is an image shipped with Image Processing Toolbox with non-uniform illumination. Take a look at that example to see how you could use it:
It's hard to add non-uniform background illumination to images. That would be hard even with Adobe Photoshop. It's easier to create a non-uniform background and then add the foreground. So, why not create images from the ground up using basic functions in MATLAB?
Here's a code snippet that creates a grayscale image with a non-uniform background made of a sinc wave:
    
    N = 500;
    
    
    x = linspace(-50,50,N);
    y = linspace(-50,50,N);
    
    [X,Y] = meshgrid(x,y);
    
    r = sqrt(X.^2 + Y.^2);
    
    background = sin(r)./r;
    
    mmin = min(background(:));
    mmax = max(background(:));
    
    background = 255*(background-mmin)/(mmax-mmin);
    
    background = uint8(round(background));
    
    figure
    imshow(background)
    
    img = background;
    img(100:200,100:200) = 255;
    img(150:450,150:350) = 128;
    
    imshow(img)
You could also do a gradient across the image. For example:
    
    x = linspace(100,200,N);
    y = 1:N;
    
    [X,Y] = meshgrid(x,y);
    
    background = uint8(round(X));
    
    imshow(background)