In this video I’m going to show you how to use the Presence/Absence widget in Clarity. With Presence/Absence you can detect if something’s there or not there, depending on what you want to do. In this case I’m using pre-canned images that are on my desktop, which is normally how you’d develop a machine vision application, you would capture the images, you would store them on your laptop, and later on you would test in the live camera. And I’ll show you how to do that at the end.
What I’m going to do today is show you several different Presence/Absence functions. I’m going to show you how to detect if the test tube is present, I’m going to show you how to detect if the cap is present, and I’m going to show you how to detect if the barcode is present.
So let’s start out with the test tube body. I’m going to add a Presence/Absence widget [from the top menu bar]. You can see how it shows up over here in our step list [to the left]. Then I have this region of interest [highlighted block], so I’m going to place this region of interest right over the test tube itself. Then I’m going to select the Threshold method of Presence/Absence [below the image]. There are several different methods you can choose, so I’ll be exploring several of those today [at bottom below image].
The next thing I’m going to do is to set the pixel values that I want look at. So you can see how Clarity presents a histogram of the image that is up here. It’s actually of the region of interest at this point, and you can see how that histogram will change as I move the region of interest around [moving over picture with mouse]. I’m interested in this histogram here. So how I’m going to set this up is that I’m going to look for bright pixels, because if that test tube isn’t there I’m going to see this bright background. So I’m going to exclude below 200 [pixels]. I only want to be counting the bright pixels. I can set my threshold automatically or I can set it manually. In this case, I’m going to set it manually. Let’s set it up to 225 [moved the Threshold bar to 225]. I’m only going to look at pixels between 200 and 225, and I’m going to have a further threshold of above 225 where I’m going to consider them. Then I’m going to look at my Passing Range, and I’m going to set from 0 to 200 pixels. What this is saying is that if I have anywhere between 0 and 200 pixels that are above 224 counts, then my test tube is there. An alternate way to say it is here’s a case where my test tube is not there, and you can see I have over 7,000 of those bright pixels available, and so the step fails. I can set the name of that step to be “test tube present?” to make it more obvious what the step is actually doing.
Okay, the next thing I’m going to do is to add another present step to check for cap presence. So I’m going to add another step, and let’s make this step “cap present?” I’m going to go down here, and I’m going to select a different method to show you how it works. I’m going to select a Brightness method. Again, I have a region of interest, so I’m going to set that over this cap. And you can see my average value of Brightness, the average pixel value of that region is 67. And then I’m going to leave this alone, but I’m saying I only want to say the cap is there if this brightness value is low. So anywhere between 0 and about 150, if my average brightness value is between 0 and 150, then that cap is there. So let’s test that out. You can see my average value went to 255, because of this bright background I have, and so it fails because the cap is not there.
Now I’m going to go back to my first image. And I’m going to do one more thing, I’m going to look for that barcode. So let’s add another Presence/Absence step, and this time I’m going to choose the Edge Pixels method. In this barcode I have a lot of nice edges, which are the transitions between blacks and whites in the image. So I’m going to set up an area to look for those. Again, let’s change the name of our step to “barcode present?” I’m going to set my Edge Magnitude pretty high. I have really nice black and white edges here, so I’m not going to accept a magnitude transition between a black and a white that’s any less than 50 counts. Potentially I could make that higher, but I think it’s a pretty good value to start. The other thing I have to do is set the direction of the edges. That gets a little bit more complicated. So you can imagine on this dial that the center white circle is a pixel in the image. So you take any pixel in the image and it’s going to search in that horizontal direction looking for edges. We’re not interested in edges that are in this direction [moving dial in circle], we’re only interested in those barcode edges which are vertical in the image or orthogonal to this pixel. The other thing you should know is that Clarity sets up, is automatically looking for edges that go black to white. We’re also going to say we want to look for white to black edges. So this direction on the dial is white to black edges. You can see with this barcode that I have 729 Edge pixels. So what I’m going to do is change my pass criteria. If I have anywhere between 100 and let’s say 2000 Edge pixels, then that barcode is present. Now let’s test it out. Okay that’s good. It failed when there’s no tube present. We have another image that the barcode is present, but the cap is not. Then I have another image where the tube is present, cap is present, but the barcode is turned around. You can see that also fails.
The last thing I’m going to do is add an output step. Now that we have Clarity running and working, we have to have some way of communicating the results to our host. So I’m going to take the output, and the first thing I’m going to do is for each of these steps I’m going to add some kind of text string and the results.
So let’s start out I’m going to add text, I’m going to add output, and I’m going to change this to “tube present.” Then I’m going to take the test tube present result. I’m going to take all of these parameters that I can output to. I can see all of these different parameters which I can output. I can output the result itself which is what I’m interested here, but I can also output the time, the number of pixels, the pixel count for that particular region of interest, the actual threshold used, and so on.
I’m going to add another text string and say “Cap Present,” then let’s add our Cap Present result. Then I’m going to add one more text string “Barcode Present,” and then let’s add our Barcode Present result. And now I can go and see what the output looks like. In this particular case, you can see Tube Present is true, Cap Present is true, and Barcode present is false.
I can run on this one [new image], where they should all be true, true, true. I can add a little delimiter here between these steps to make it clear. Next one, I get there’s no tube, no cap, no barcode. Then the last image, tube is there, cap is not there, but the barcode is there.
So this is a quick way you can take a look at using Presence/Absence to detect something in the image.