So now we move on to Section 21, which is filtering colors.
So go ahead and open this notebook.
So if this thing is seen, this input, which I've highlighted here, is this HSV color space.
Now, I don't know if you recall from our earlier lesson where we talked about the HSV color space stands
for Hue saturation and the value.
Basically, this allows us to this this color space allows us to filter on colors.
And the reason is because we can actually filter on Hue quite easily.
You can just extract ranges between values.
Here would be it's much, much, much more difficult to actually filter out a specific color, mainly
because different combinations of RGV give different colors.
So it's I mean, you can do it.
It's just much harder than HSV makes it much easier.
So let's move on.
So firstly, let's load all images and libraries and create a major function, which I've done already.
You can go ahead and run this block of code.
So what we're going to do, we're going to actually create a filter that basically removes the truck
and this land here and only keeps the sky.
So we're making a blue or purple filter.
So to do that, you can see we need to defined an upper and lower range.
So this upper and lower was this one up, I should say, started at 90.
Remember, this is each.
So we go from 90 to 125, that's all orange.
And then we go zero to 255 30 to 50 540 saturation in value.
Since we we don't we don't care about saturation and value.
Even though we can, we can make filters for this.
In this case, we just want to get all the ranges of the blue.
So 90 to 135, let's go back up to a color wheel 90.
You can see is where the blue starts around here and one two five is red and basically here.
So even though I did call the purple, it's actually a blue filter.
Not then why I left purple then.
So let's run this block of code and we can see the outputs and I'll go back and you can see it's exactly
what we wanted.
Now you can see there's an interim image here, which is a banner raised image that looks a bit like
a mask.
And that's because it is a mask.
So let's go over to code here.
So what we did first thing, we loaded the image, we defined our ranges and then we converted to the
color image to an HSV image.
And then we use the C v2.0 in range of function with the upper limit and lower image here.
Sorry, and the image on the upper, the lower and upper limits.
And that gives us a mess.
The mask is a binary threshold at image, which basically tells us gives us everything.
That's everything that's in the filter is white on it.
So it's a yes, and everything that's not in the filter range is black.
So that's like a.
And do you remember our Bitwise operations?
Well, we can use a Bitwise operation and which basically tells us that if we do use and with this image
and our mask and the statistics and image twice, you know, if you recall in a previous lesson, we
can actually create this nice filter here.
So you can see we've extracted everything except the blue sky, which is pretty cool.
Filtering is actually really good if you want to isolate, see on like a tennis ball, which you know
is a specific color or cricket ball, which would be red or white.
So all basketball would you be orange?
So you can do the filters and then do tracking like that.
It works quite well.
So let's do this.
Let's actually look up that color wheel.
What if we wanted to filter on the red?
You can see red is a bit tricky because red is at the threshold down here.
Right here, red actually goes from zero to maybe around 15.
And then all the way back down to this is this is a 180 here.
So 180 to maybe like 160.
But that's a problem because now we have two oranges, we have zero to 15 and then one, 65 to 180.
So how do we do it with two color ranges?
Well, it's it's actually not that hot, but we do have to specify to mess.
So you create a mask, the a mask, which is the zero to 10, and then we create other masks, which
is 170 to 180, and we create the mask is Mesirow Mask one.
So then we joined the mask together by adding them, and then we can do the same Bitwise operation again.
So in this image with Hillary Clinton, we're going to filter out the Reds in the image.
So let's run this code.
Images and find.
Oh, that's because this variable needs to be image here.
So sorry for my mistake.
OK, so there we go.
So it works now, so you can see this is a mess that we added together so we can actually get everything
that's ready.
Or at least reddish tint skin tones apparently were red in this image and actually do tell it this bit
red.
That's why it was in that color range, and that's left.
So we get scary vision of Hillary Clinton with missing teeth and missing here.
But it's OK.
Sorry, Hillary.
And we have her red dress filtered, so that's pretty cool.
So that concludes this lesson and color filtering.
It's a very useful lesson for many different applications, so it's a good thing.
It's named filtering colors.
It's easy to find.
So we will now move on to something called the watershed algorithm, which is a marker based image segmentation
algorithm.
So stay tuned and I'll see you in the next lesson.
Thank you.