Threshold list in image.get_statistics and find_blobs

Discussion related to "under the hood" OpenMV topics.
GL-ITC
Posts: 58
Joined: Tue Feb 25, 2020 7:09 am

Threshold list in image.get_statistics and find_blobs

Postby GL-ITC » Thu Mar 05, 2020 8:18 am

Hi,

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?

Code: Select all

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.
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Threshold list in image.get_statistics and find_blobs

Postby iabdalkader » Thu Mar 05, 2020 10:22 am

GL-ITC wrote:
Thu Mar 05, 2020 8:18 am
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.
These are two separate functions, you can use get_statistics without finding blobs first, then you'll need to pass a threshold.
GL-ITC
Posts: 58
Joined: Tue Feb 25, 2020 7:09 am

Re: Threshold list in image.get_statistics and find_blobs

Postby GL-ITC » Thu Mar 05, 2020 10:55 am

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.
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Threshold list in image.get_statistics and find_blobs

Postby iabdalkader » Thu Mar 05, 2020 11:04 am

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.
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Threshold list in image.get_statistics and find_blobs

Postby iabdalkader » Thu Mar 05, 2020 11:19 am

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:

Code: Select all

        stats = img.get_statistics(thresholds=threshold_list, roi=blob.rect())
        stats2 = img.get_statistics(roi=blob.rect())
        print(stats==stats2)
You can still drop the threshold arg, but it will include all the pixels in that blob.
GL-ITC
Posts: 58
Joined: Tue Feb 25, 2020 7:09 am

Re: Threshold list in image.get_statistics and find_blobs

Postby GL-ITC » Thu Mar 05, 2020 11:25 am

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

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 15 guests