function [id1 id2 id3] = imgDiff(refImg,img1,img2,img3)
% This function prodcues the "difference" images that are used to find the
% LED postion. Firstly the difference between each image and the reference
% frame is determined. However, this difference frame often contains a lot
% of extra difference data which can often lead to incorrect detection
% points. By removing the difference data off the other frames as well a
% much better result is obtained.
% Inputs:
% refImg: image to which the other images are compared
% img1,img2,img: the images that contain a lit LED
% Outputs:
% id1,id2,id3: The resulting difference images


refImg = medfilt2(refImg);
img1 = medfilt2(img1);
img2 = medfilt2(img2);
img3 = medfilt2(img3);

%get the difference between te reference image and the lit image
i1d = imsubtract(img1,refImg);
i2d = imsubtract(img2,refImg);
i3d = imsubtract(img3,refImg);

%Remove extra difference information found in the other difference images
id1 = imsubtract(imsubtract(i1d,i2d),i3d);
id2 = imsubtract(imsubtract(i2d,i1d),i3d);
id3 = imsubtract(imsubtract(i3d,i1d),i2d);
