Threshold list in image.get_statistics and find_blobs


Can you explain to me the purpose of passing the color threshold list to the find_blobs and image.get_statistics function. The issue I am having is if the find_blobs function is finding blobs that meet the color thresholds and the other threshold parameters, why does the image.get_statistics function need to be supplied with the threshold list again within the find_blobs loop?

for blob in img.find_blobs(threshold_list, pixel_threshold=pixel_thresh, area_threshold=area_thresh, margin=5, merge=False):
        roi_count = roi_count + 1
        img.draw_rectangle(blob.rect()) #draws a rectangle (x, y, w, h) around blob for bounding box
        stats = img.get_statistics(thresholds=threshold_list, roi=blob.rect()) #get statistics for each blob where the blob is the roi.
        img.draw_string(blob.x(), blob.y() - 10, "%.4f C" % map_g_to_temp(stats.mean()), mono_space=False)

As an example if I am only looking for 1 color tuple of (120, 255) why do I need to supply this again to the get_statistics function, shouldn’t it just take the average of everything within blob.rect() as its already gone through a color threshold test in the find_blobs function.

In your documentation on the image.get_statistics function you say :

If you pass a list of thresholds then the histogram information will only be computed from pixels within the threshold list.

I don’t understand the logic behind providing the threshold list to the get_statistics function if it has already been used by the find_blobs function?

Hopefully I’ve explained myself well enough so you can understand my point of view.

These are two separate functions, you can use get_statistics without finding blobs first, then you’ll need to pass a threshold.

Sorry I’m still a bit confused. I understand that they are two separate functions and that they can be called independently of each other. In the documentation for the get_statistics function on the thresholds attribute specifically it says

Only pixel regions that fall between these thresholds will be considered

. My understanding was that the find_blobs function had already found these regions that met the threshold requirements so in the code example i gave you earlier im not sure what the image.get_statistcs function is doing with the threshold paramerter. I only use the function so I can map the average pixel value withing the blob to a temperature value and then display it outside the boundary box.

Because it’s a required arg, it must be passed again to get_statistics, but I see your point, maybe it should be optional.

EDIT: It’s not actually a required arg, you should be able to just ignore it.

Actually the returned blob will have pixels outside the threshold (it’s just a rectangle containing that area), so you need to pass the threshold list again to get_stats, here’s a simple test that fails:

        stats = img.get_statistics(thresholds=threshold_list, roi=blob.rect())
        stats2 = img.get_statistics(roi=blob.rect())

You can still drop the threshold arg, but it will include all the pixels in that blob.

Ah ok, I see what you mean. Thank you.