MATLAB: Foreground Object Detection from Reconyx Camera Trap Images

image processingImage Processing Toolboximage segmentation

I have a series of images (upwards of 100) from a Reconyx motion triggered camera, observing a compost pile, with images of animals present in the scene. They are not in constant seqeunce (i.e not like you would expect if you took a video fram by frame). What would be the best method to obtain the contours or the edges of the animal(s) present in the images while removing the background(noting that all of the images more or less share the same background). Attached are some images with just the background, and some with animals present in the foreground.

Best Answer

I'd subtract the background from the test image, then threshold and do some size filtering, then mask.
diffImage = abs(double(grayImage) - double(backgroundImage));
animalMask = diffImage > 5; % Whatever works
animalMask = imfill(animalMask, 'holes');
animalMask = bwareafilt(animalMask, [100, inf]); % Take only the larger blobs.
maskedImage = grayImage; % Initialize.
maskedImage(~mask) = 0; % Or whatever gray level you want, such as mean(grayImage(~mask));
Adapt as needed. Let me know if you still need help.