MATLAB: Is there a way to apply a threshold to regionprops/bounding boxes

activecontourbounding boxenvelopeimage processingImage Processing Toolboxregionprops

I'm working with data from a Pedobarograph (see example images below).
What I want MATLAB to do, is to define bounding boxes around each separate foot. Most of the time, the foot doesn't land firmly on the mat in a way that would make the toes, heel etc. contiguous. This means when I use regionprops, I end up with about dozen regions per image, even though there are only four feet in each.
So is there a way to apply some type of threshold to regionprops? Such that rather than defining a region by contiguous elements (i.e. zero, zero elements between), the threshold would allow n number of zero elements between?
Any other suggestions to select each separate foot would be much appreciated. I can provide more information if required.
Thank you!

Best Answer

Well, there are several ways to deal with it. One way is to use activecontour() to find a snug "envelope" for each collection of blobs. That's what my attached demo does.
Another way is to use imclose() to try to attach all nearby blobs. Use a structuring kernel that is small enough to not connect blobs from different footprints.
There might be other ways that might be required for pathological images if neither of those two methods work. Let us know if another method is required because those two fail, and attach the image that doesn't work.
Upload your original gray scale image if you want more help.