Blob Statistics - stats of blob instead of rect?

Is there any way to get the histogram/stats of just the blob rather than the bounding rect? In the attached photo, we are finding healthy and unhealthy leaves. I want to get statistics on the blobs that we find, but I’m forced to get the stats for the bounding rect instead of the actual blob itself. Is there anyway to show the stats of the actual blob?

I’m more or less trying to get a better look at exactly what stats each of our blobs has to better identify healthy vs. unhealthy leaves when they’re not quite as obvious as below.

Ah… I see what you need me to do. I’ll have to add this to the firmware. Basically, you need me to constrain the histogram given a rect to the color thresholds you used for the blob. We had this same feature on the CMUcam4.

I can have this done for you by tomorrow. It’s very easily. I just have to add a threshold test to get_histogram().

Hi, this firmware does what you need.

Call get_histogram() or get_statistics() with the new “threshold = [ (,), (,), etc. ]” and “invert = bool” args. These work just like on find_blobs. If you don’t pass the threshold list get_* works like normally. If you pass the threshold list only color values in the threshold list will be applied to the histogram/stats, use invert to invert the matching process. So, just pass the same thresholds that made the color blob to the get_histogram() method. If you need to lookup what thresholds made the color blob use the color blobs .code() value which will return the (1 << index) of the color in the list of colors you passed to find_blobs(). E.g.

threshold_list = [...]
for blobs in img.find_blobs(threshold_list):
    stats = img.get_stats(roi=blob.rect(), thresholds=[threshold_list[int(math.log2(blob.code()))]])

It’s cool how much you can do in so few lines of code. I love python on microcontrollers. (2.05 MB)