I have a suggestion, but I want to be clear that this is not something i've tried, so i'm not sure it will work. But it'd be pretty cool if it did :) You will probably need to adjust this some, but here it is:
1. Create a mask image for your ROI such that the pixels in the ROI are 1, those outside it are 0.
Your life will be much easier if you just create masks of the outlines of the blobs/islands, without
the islands being filled, but i'm not sure if you can do that. I'd have to think more about it and dont
have time at the moment.
2. Call FIND_BOUNDARY() using the output of #1 as input. Download FIND_BOUNDARY() at
http://www.dfanning.com/p...s/find_boundary.pro.
3. If FIND_BOUNDARY() succeeds, set pixels in the mask at the boundary it finds to 0, and increment
a counter variable.
4. Repeat step 3 until no more boundaries are found.
Later in the week when i have some time i'll try this myself to see if i can get it to work. FIND_BOUNDARY() can give weird results sometimes, particularly if the blobs/islands are tiny, but for ROI's in an image I think it might be ok.
Jeff