From my understanding you want to substract two images. You can simply do
a = imread('image1.jpg');
b = imread('image2.jpg');
SubImage = double(a) - double(b);
imshow(SubImage, []);
If in case you want to substract with all the images just do it using a for loop.