How can I find and remove overlays from the list?

I divided the image into objects (fragments), using the method kindly provided by unutbu and Joe Kington, to this question: The rectangular bounding box around the drop in a monochrome image using python and have a list of these objects that takes the following form:

the_blobs = [(slice(dy.start, dy.stop, None), slice(dx.start, dx.stop, None))] 

dy.start gives the initial y-pixel value, and dy.stop gives the final y-pixel value and the same deal for dx.

Inside the list there are some objects that overlap, i.e. one tiny object (square) is inside a larger object, such as a circle. When this happens, I want to remove the β€œclosed” object from the list (since the circle has already included it), for example.

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))] 

perfect list (with deleted object)

 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))] 

It should be noted that within the framework of the above question, it was proposed 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 does not work in 100% of cases, and it really was a contribution slightly beyond the scope of the original question, so I re-open this part as a separate specific question.

Any ideas on how I can achieve this?

objects as shown in list

EDIT: Here is an example of an actual image that does not work with the above code.

enter image description here

processing returns

enter image description here

and

enter image description here

Ideally, I would like to remove the last image from the list of fragments

+3
source share
1 answer

Obviously, you can use the O (n ^ 2) approach, which checks each block on all other blocks and determines whether it should be deleted by checking if blob1.dx.start > blob2.dx.start and blob1.dy.start > blob2.dy.start and blob1.dx.stop < blob2.dx.stop and blob1.dy.stop < blob2.dy.stop (if this condition is true, it is normal to remove blob1 from the list). If your overall blob count is pretty low, this should work if I don't miss anything.

If you are looking for an optimized solution, it would be useful to know how many blocks there are and how common this condition is.

+1
source

Source: https://habr.com/ru/post/909787/


All Articles