Ask Your Question
0

Python efficiently filter blobs

asked 2015-04-09 05:32:52 -0500

_chris gravatar image

I'm segmenting an image and have a good threshold performed, however I need to remove areas which are too large or too small. My current implementation works, but I feel there has to be a quicker way.

def consecutive(data, stepsize=1):
    return np.split(data, np.where(np.diff(data) != stepsize)[0]+1)

# Remove blobs which aren't right size
# Go through rows
for row in thresh:
    ret = consecutive(np.where(row))
    for line in ret:
        if line.size > 200 or line.size < 30:
            row[line] = 0
# Go through columns
for row in thresh.T:
    ret = consecutive(np.where(row))
    for line in ret:
        if line.size > 200 or line.size < 30:
            row[line] = 0

The general idea of this is shown below (trying to isolate the LED - the middle image is the end result). Are there any built in ways to achieve this more efficiently?

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-04-09 10:19:08 -0500

Haris gravatar image

updated 2015-04-09 10:20:50 -0500

Probably the contour processing works here,

You can do the following,

Note: If you already segmented the object then perform the last two steps only.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-09 05:32:15 -0500

Seen: 397 times

Last updated: Apr 09 '15