1
00:00:00,060 --> 00:00:04,070
So now we move on to Section 21, which is filtering colors.

2
00:00:04,110 --> 00:00:06,360
So go ahead and open this notebook.

3
00:00:06,870 --> 00:00:11,370
So if this thing is seen, this input, which I've highlighted here, is this HSV color space.

4
00:00:11,910 --> 00:00:16,950
Now, I don't know if you recall from our earlier lesson where we talked about the HSV color space stands

5
00:00:16,950 --> 00:00:18,940
for Hue saturation and the value.

6
00:00:19,590 --> 00:00:24,540
Basically, this allows us to this this color space allows us to filter on colors.

7
00:00:24,840 --> 00:00:28,620
And the reason is because we can actually filter on Hue quite easily.

8
00:00:28,650 --> 00:00:31,590
You can just extract ranges between values.

9
00:00:31,590 --> 00:00:38,520
Here would be it's much, much, much more difficult to actually filter out a specific color, mainly

10
00:00:38,520 --> 00:00:42,080
because different combinations of RGV give different colors.

11
00:00:42,090 --> 00:00:43,590
So it's I mean, you can do it.

12
00:00:43,620 --> 00:00:46,230
It's just much harder than HSV makes it much easier.

13
00:00:46,920 --> 00:00:48,420
So let's move on.

14
00:00:48,690 --> 00:00:55,410
So firstly, let's load all images and libraries and create a major function, which I've done already.

15
00:00:55,470 --> 00:00:57,960
You can go ahead and run this block of code.

16
00:00:58,620 --> 00:01:06,120
So what we're going to do, we're going to actually create a filter that basically removes the truck

17
00:01:06,120 --> 00:01:09,030
and this land here and only keeps the sky.

18
00:01:09,060 --> 00:01:11,160
So we're making a blue or purple filter.

19
00:01:11,640 --> 00:01:15,660
So to do that, you can see we need to defined an upper and lower range.

20
00:01:16,170 --> 00:01:20,580
So this upper and lower was this one up, I should say, started at 90.

21
00:01:20,610 --> 00:01:21,750
Remember, this is each.

22
00:01:22,020 --> 00:01:24,990
So we go from 90 to 125, that's all orange.

23
00:01:25,590 --> 00:01:29,910
And then we go zero to 255 30 to 50 540 saturation in value.

24
00:01:29,910 --> 00:01:32,520
Since we we don't we don't care about saturation and value.

25
00:01:32,520 --> 00:01:35,580
Even though we can, we can make filters for this.

26
00:01:36,120 --> 00:01:38,550
In this case, we just want to get all the ranges of the blue.

27
00:01:39,060 --> 00:01:43,450
So 90 to 135, let's go back up to a color wheel 90.

28
00:01:44,310 --> 00:01:49,800
You can see is where the blue starts around here and one two five is red and basically here.

29
00:01:49,920 --> 00:01:54,290
So even though I did call the purple, it's actually a blue filter.

30
00:01:54,300 --> 00:01:55,800
Not then why I left purple then.

31
00:01:56,460 --> 00:02:03,120
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

32
00:02:03,120 --> 00:02:03,750
what we wanted.

33
00:02:04,140 --> 00:02:10,050
Now you can see there's an interim image here, which is a banner raised image that looks a bit like

34
00:02:10,050 --> 00:02:10,620
a mask.

35
00:02:10,980 --> 00:02:12,910
And that's because it is a mask.

36
00:02:13,320 --> 00:02:14,580
So let's go over to code here.

37
00:02:14,580 --> 00:02:19,290
So what we did first thing, we loaded the image, we defined our ranges and then we converted to the

38
00:02:19,290 --> 00:02:21,210
color image to an HSV image.

39
00:02:21,690 --> 00:02:27,270
And then we use the C v2.0 in range of function with the upper limit and lower image here.

40
00:02:27,390 --> 00:02:30,120
Sorry, and the image on the upper, the lower and upper limits.

41
00:02:30,720 --> 00:02:31,920
And that gives us a mess.

42
00:02:32,820 --> 00:02:38,820
The mask is a binary threshold at image, which basically tells us gives us everything.

43
00:02:38,820 --> 00:02:42,810
That's everything that's in the filter is white on it.

44
00:02:42,840 --> 00:02:48,100
So it's a yes, and everything that's not in the filter range is black.

45
00:02:48,150 --> 00:02:48,670
So that's like a.

46
00:02:49,560 --> 00:02:52,860
And do you remember our Bitwise operations?

47
00:02:53,280 --> 00:03:00,030
Well, we can use a Bitwise operation and which basically tells us that if we do use and with this image

48
00:03:00,480 --> 00:03:06,600
and our mask and the statistics and image twice, you know, if you recall in a previous lesson, we

49
00:03:06,600 --> 00:03:09,750
can actually create this nice filter here.

50
00:03:10,620 --> 00:03:14,730
So you can see we've extracted everything except the blue sky, which is pretty cool.

51
00:03:15,660 --> 00:03:20,040
Filtering is actually really good if you want to isolate, see on like a tennis ball, which you know

52
00:03:20,040 --> 00:03:22,920
is a specific color or cricket ball, which would be red or white.

53
00:03:23,580 --> 00:03:25,140
So all basketball would you be orange?

54
00:03:25,560 --> 00:03:27,720
So you can do the filters and then do tracking like that.

55
00:03:27,720 --> 00:03:28,590
It works quite well.

56
00:03:29,190 --> 00:03:30,750
So let's do this.

57
00:03:30,750 --> 00:03:33,300
Let's actually look up that color wheel.

58
00:03:34,140 --> 00:03:35,700
What if we wanted to filter on the red?

59
00:03:36,360 --> 00:03:39,420
You can see red is a bit tricky because red is at the threshold down here.

60
00:03:39,420 --> 00:03:43,920
Right here, red actually goes from zero to maybe around 15.

61
00:03:44,550 --> 00:03:48,960
And then all the way back down to this is this is a 180 here.

62
00:03:48,990 --> 00:03:50,970
So 180 to maybe like 160.

63
00:03:51,540 --> 00:03:57,270
But that's a problem because now we have two oranges, we have zero to 15 and then one, 65 to 180.

64
00:03:57,690 --> 00:04:00,000
So how do we do it with two color ranges?

65
00:04:00,600 --> 00:04:05,930
Well, it's it's actually not that hot, but we do have to specify to mess.

66
00:04:06,420 --> 00:04:11,970
So you create a mask, the a mask, which is the zero to 10, and then we create other masks, which

67
00:04:11,970 --> 00:04:17,370
is 170 to 180, and we create the mask is Mesirow Mask one.

68
00:04:18,030 --> 00:04:23,700
So then we joined the mask together by adding them, and then we can do the same Bitwise operation again.

69
00:04:24,120 --> 00:04:28,110
So in this image with Hillary Clinton, we're going to filter out the Reds in the image.

70
00:04:28,620 --> 00:04:30,270
So let's run this code.

71
00:04:33,150 --> 00:04:34,410
Images and find.

72
00:04:38,110 --> 00:04:42,520
Oh, that's because this variable needs to be image here.

73
00:04:42,700 --> 00:04:45,370
So sorry for my mistake.

74
00:04:46,510 --> 00:04:47,550
OK, so there we go.

75
00:04:47,600 --> 00:04:53,290
So it works now, so you can see this is a mess that we added together so we can actually get everything

76
00:04:53,290 --> 00:04:53,890
that's ready.

77
00:04:53,890 --> 00:04:58,940
Or at least reddish tint skin tones apparently were red in this image and actually do tell it this bit

78
00:04:58,960 --> 00:04:59,220
red.

79
00:05:00,370 --> 00:05:03,640
That's why it was in that color range, and that's left.

80
00:05:03,820 --> 00:05:09,640
So we get scary vision of Hillary Clinton with missing teeth and missing here.

81
00:05:10,300 --> 00:05:10,930
But it's OK.

82
00:05:11,170 --> 00:05:11,890
Sorry, Hillary.

83
00:05:12,610 --> 00:05:15,580
And we have her red dress filtered, so that's pretty cool.

84
00:05:16,060 --> 00:05:18,390
So that concludes this lesson and color filtering.

85
00:05:18,400 --> 00:05:22,870
It's a very useful lesson for many different applications, so it's a good thing.

86
00:05:22,870 --> 00:05:24,150
It's named filtering colors.

87
00:05:24,160 --> 00:05:24,880
It's easy to find.

88
00:05:25,390 --> 00:05:31,810
So we will now move on to something called the watershed algorithm, which is a marker based image segmentation

89
00:05:31,810 --> 00:05:32,350
algorithm.

90
00:05:32,620 --> 00:05:34,780
So stay tuned and I'll see you in the next lesson.

91
00:05:35,020 --> 00:05:35,440
Thank you.
