Ask Your Question

mean color of a blob calculated in another image

asked 2012-07-22 00:05:24 -0500

kespindler gravatar image

I have code essentially like the following:

img = Image('myimg.jpg')
binimg= img.binarize()
blob = binimg.findBlobs()[0]

Now, I need the mean color of the blob as calculated from img. That is to say, right now, blob.meanColor() is (255, 255, 255), because the blobs were calculated off the binarized image. Doing something like (img.crop(blob) - blob.blobMask().invert()).meanColor() doesn't exactly work because that's going to be negatively weighted by all the black surrounding the blob.

Any ideas? Seems like this should be really easy to do, and I'm just missing something obvious.

edit retag flag offensive close merge delete


(img.crop(blob) - blob.blobMask().invert()).findBlobs((0,0,0))[0].meanColor() doesn't even work perfectly, but is close to what I'm after. But god, seems like a ridiculous work around to redetect the blobs. Better solution would be awesome!

kespindler gravatar imagekespindler ( 2012-07-22 00:11:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-25 09:14:56 -0500

kscottz gravatar image

Oh, super simple. I would search the documentation on git. We have a couple different variants on findBlobs. Sorry for the delay getting back to you.

img = Image('myimg.jpg')
binimg= img.binarize()
# binarize is applied first then blobs are returned
blob = img.findBlobs()[0]
# Let's say we wanted to apply a morph operation to our binary image.
blob2 = img.findBlobsFromMask(binimg.dilate())
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-07-22 00:05:24 -0500

Seen: 348 times

Last updated: Jul 25 '12