I have divided an image into objects (slices) using the method kindly contributed by unutbu and Joe Kington at this question: Rectangular bounding box around blobs in a monochrome image using python and have a list of these objects which takes the following form:
the_blobs = [(slice(dy.start, dy.stop, None), slice(dx.start, dx.stop, None))]
dy.start gives the starting y-pixel value and dy.stop gives the final y-pixel value, and the same deal for dx.
Within the list there are some objects which overlap i.e. one tiny object (a square) is within a larger object such as a circle. When this occurs I want to remove the "enclosed" object from the list (because the circle already has it included) e.g.
current list
the_blobs = [(slice(100L, 1000L, None), slice(100L, 1000L, None)),
(slice(150L, 220L, None), slice(150L, 220L, None)),
(slice(1001L, 2000L, None), slice(1500L, 1700L, None)),
(slice(2001L, 2200L, None), slice(1800L, 1890L, None))]
ideal list (with object removed)
the_blobs = [(slice(100L, 1000L, None), slice(100L, 1000L, None)),
(slice(1001L, 2000L, None), slice(1500L, 1700L, None)),
(slice(2001L, 2200L, None), slice(1800L, 1890L, None))]
I should note that as part of the aforementioned question a suggestion was made to use the following code:
data_slices = ndimage.find_objects(coded_paws)
for s in data_slices:
filled[s] = True
coded_paws, num_paws = ndimage.label(filled)
data_slices = ndimage.find_objects(coded_paws)
However this doesn't seem to work 100% of the time, and it really was a contribution slightly beyond the scope of the original question so I'm re-opening this part as a separate, specific question.
Any ideas on how I can achieve this?
EDIT: Here's an actual image example which doesn't work with the above code
processing this returns
and
Ideally I'd like to remove the last image from the list of slices