Dynamic Thresholding

This tutorial shows how to effectively use the Variable_Tuning module to determine an appropriate configuration to segment the end of a steel plate just after fabrication while it is still visibly glowing. The need is to be able to track where the steel plate is on the rollers to know (a) that a plate is present, (b) the location of the plate and (c) its approximate temperature.

The following images are used as examples to help experiment with various techniques.




In order to determine the position of the plate we need to be able to reliably segment out the front side of the plate which can be used to determine position. This means we want a collection of pixels (i.e. blob) that best represents the front of the plate without it touching any other blob/part of the image. This is needed in order to isolate the front from the rest of the image using blob filtering techniques.

An attempt to use the static Threshold module at a 105 intensity threshold would produce the following images two images where the steel plate is present:

Hot Threshold 105 (good)

Warm Threshold 105 (bad)

This works to isolate the front side for the hotter temperature plate but completely removes the desired detection on the colder plate. Likewise, if we threshold at 15 we get the following images:

Hot Threshold 15 (bad)

Warm Threshold 15 (good)

This lower threshold works for the colder plate but completely fails on the hotter plate. This is expected since the two plates have very different intensity levels and finding a single level that works to segment exactly what we want from the image is not possible. With this in mind, we would normally try to use a more advanced thresholding technique like the Adaptive Threshold which can be used when a single threshold level isn't easy to find. Our best efforts using this module produce:

Hot Adaptive 69, -17 (ok)

Warm Adaptive 69, -17 (bad)

These are better results but the hotter plate almost merges with other parts of the image and the warm plate is almost segmented out completely. One can improve the results using a combination of erosion and dilation in an attempt to reconstruct some of the removed pixels but that solution does not work reliably across more test images.

Instead of attempting to find the perfect segmentation value or technique, let's assume we can use the two simple threshold levels from above (105 and 15) with the appropriate image. Assuming we have a good threshold value we can continue with processing the image using the Blob Filter module. In this case we use two filters to ensure that only blobs larger than 10,000 pixels and smaller than 15,000 pixels remain. Using two threshold values followed by the blob size filters yields the following images:

Hot Filtered (105 threshold)

Warm Filtered (15 threshold)

Obviously since we manually determined what the needed threshold values were for each image we get very good results. The way we accomplished this was to watch the results of the Blob Filter while manually adjusting the threshold level until we saw the desired result. While this technique works, it cannot be used in practice since we wish to automate this segmentation process rather than have a human be involved in the process.

To automate this technique we can use the Variable Tuning module. We know that the desired solution should provide us with one remaining blob (the front of the steel plate) that has a size between 10,000 and 15,000 pixels. What we don't know is what the needed threshold value is in order to achieve this outcome. We will use the Variable Tuning module to discover this value.

A precursor to using the Variable Tuning module is to replace static values with variables. In our case, this requires us to replace the 'From' value in the simple Threshold module with the variable [threshold]. The '[' and ']' tell the module to use the value in the variable 'threshold' instead of a static numerical value. You can read more about these variable expressions here.

Once this change to the Threshold module is done, we enter that variable into the Variable Tuning module and let it know that we expect the value to be from 5 to 255 (the intensity range for a single 8 byte number) and, most importantly, that a successful result is when only one blob is left between the desired sizes. This is specified in the Output section of the Variable Tuning module interface, i.e. Blob_Count = 1. The Blob_Count variable is created by the Blob_Filter module as part of its results.

When we run the Variable Tuning module just once for each image (by pressing the Tune Once button) you will see it cycle through various threshold levels until it runs through all 250 of them (255 - 5 = 250). The following results can be seen.

Hot Tuned (bad)

Warm Tuned (good)

Unfortunately, the tuning picked up on another blob that met the size criteria for the Hotter plate. The Variable Tuning module will explore many possibilities that fit the exit criteria and if the desired outcome is not well specified you will get unexpected results. To remedy this, we add a 3rd criteria in the Blob Filter module, specifically, the Diagonal Right feature which will be higher for our desired blob than the mistake we currently have which is more left diagonal.

Pressing the Tune button again on the Variable tuning will now result in:

Hot Tuned (good)

Warm Tuned (good)

Success! We now have the Variable Tuning module picking out the right blobs using the default Exhaustive Search technique. Typically you will want to search quicker than using the Exhaustive Search. Clicking on the Random radio button in the Technique group in the Variable_Tuning module might not be as optimal as the Exhaustive search but it will really speed up finding a solution. In our case, when we do this, we find another error in one of the images.

Warm Error

This blob meets all the criteria in the Blob Filter which is why it can be a solution that stops the random search. To eliminate this from being a possible solution we add a final 4th criteria to the Blob Filter called Boxed that will eliminate this blob as potential solution. Once we have tested using the Random technique to ensure we consistently get the right results, we then switch to the Exhaustive First technique and increase the increment to 5 to help speed up the solution search. You can continue to focus the parameters (perhaps starting from 20 instead of 5) to keep the search flexible but reduce the number of times an image needs to be processed to find a good solution.

Now that we have the Variable_Tuning module working, we enable two features in that module to avoid us having to press the Tune button each time. The first is to add in the End_Variable_Tuning tag by selecting that checkbox in the Variable_Tuning module. This allows us to specify which modules in the pipeline are the ones that are used to find a solution. This can help speed up the processing as only those modules contained within the Variable_Tuning and End_Variable_Tuning lines in the pipeline will be run more than once. In our case this is the Threshold and Blob_Filter modules.

Second, we press the Tune Continuous button (that was enabled by selecting the End_Tag checkbox) which will cause the tuning/search to happen each time the pipeline iterates. Once this is pressed, it will change its text to STOP. Now any time a new image is captured by the application, the tuning module will run until it finds the BLOB_COUNT = 1 result. This means that we no longer need to press the Tune button as this is happening live for each new image.

You can how test all three images (with the addition of the Blob_Replace module) to show which parts of the original image we have detected.

Hot Result (good)

Warm Result (good)

Missing Result (good)

Given these results we now know all we need about the steel plate:

(a) a plate is present when the variable BLOB_COUNT = 1
(b) the location of the front plate can be determined by the Blob_Replace_Coordinates (8 numbers, 2 for each corner)
(c) the approximate temperature of the plate is related to the [threshold] variable used! The hotter plate will have a higher threshold (105) than the cooler plate (15).

Download the  Dynamic Thresholding robofile to see the steps and more about the modules used.

The End

That's all folks. We hope you've enjoyed this little adventure into an application of machine vision processing and have inspired you to download a free trial.

If you have any questions or comments about this tutorial please feel free to contact us.

Have a nice day!

 New Post 

Blob Tracking Related Forum PostsLast postPostsViews