1
00:00:00,120 --> 00:00:06,300
So now let's take a look at the second lesson in this open TV chapter, and that's called grace killing

2
00:00:06,300 --> 00:00:06,690
images.

3
00:00:06,690 --> 00:00:08,910
So let's open this file by double click and it's on.

4
00:00:08,910 --> 00:00:13,260
It's here and it opens the notebook and a new window, as you can see.

5
00:00:13,950 --> 00:00:15,330
We don't need to see this.

6
00:00:16,080 --> 00:00:17,760
So welcome to this lesson.

7
00:00:17,760 --> 00:00:19,730
So this lesson is quite simple.

8
00:00:19,740 --> 00:00:26,370
What you're going to learn to do is tick a color image, color image and convert that image into a grayscale

9
00:00:26,370 --> 00:00:26,730
image.

10
00:00:27,420 --> 00:00:28,350
Which song is simple?

11
00:00:28,540 --> 00:00:31,120
And it's actually it is very simple and open TV.

12
00:00:31,860 --> 00:00:38,610
So let's import our libraries like we did before we're importing Bud CB2 and Mark Gottlieb.

13
00:00:38,610 --> 00:00:45,530
Together, you'll see the convention in Python is actually to import all your libraries at a top of

14
00:00:45,540 --> 00:00:47,880
a notebook, followed by a Python file.

15
00:00:48,480 --> 00:00:51,390
So we will do that and most of our lessons from now on.

16
00:00:52,080 --> 00:00:57,620
So you can see we've expanded the function a bit here, the lines that are new.

17
00:00:57,930 --> 00:01:00,600
Basically, these three lines here.

18
00:01:01,530 --> 00:01:06,990
So what's different about this is that we're getting the height, the width and height from the image

19
00:01:06,990 --> 00:01:08,840
here, from the image, it's passed in the function.

20
00:01:09,900 --> 00:01:11,220
We're keeping two aspect ratio.

21
00:01:11,220 --> 00:01:16,830
We're getting the aspect ratio here because I think the width divided by the height and we do that because

22
00:01:16,830 --> 00:01:22,740
we want to actually have a parameter called size that controls the figure size of this image.

23
00:01:22,740 --> 00:01:28,500
But to ensure that the aspect ratio is maintained, we keep the aspect ratio here as an argument.

24
00:01:28,500 --> 00:01:33,800
So we have size times, debt and size him so that size.

25
00:01:33,810 --> 00:01:37,740
This is the arguments for the fixed size part of ModCloth Lib.

26
00:01:38,430 --> 00:01:41,190
So you don't need to know too much about MATLAB.

27
00:01:41,190 --> 00:01:45,300
You just need to know that this is how we adjust to figure size here, and this is how we mentioned

28
00:01:45,300 --> 00:01:47,010
the aspect ratio of our image here.

29
00:01:47,430 --> 00:01:48,960
So let's go ahead and run this.

30
00:01:48,960 --> 00:01:50,910
We've declared our function.

31
00:01:51,120 --> 00:01:54,240
We've done little files like we did in the previous lesson.

32
00:01:55,140 --> 00:01:58,470
So the image we're going to learn is a place in Tobago.

33
00:01:58,500 --> 00:02:01,800
That's my home country, Trinidad and Tobago.

34
00:02:02,220 --> 00:02:04,230
It's a beautiful beach called Star Beach.

35
00:02:04,230 --> 00:02:07,260
This is actually part of costar of Beach called Heavenly Bay.

36
00:02:08,010 --> 00:02:12,900
So we're going to load this image here and display below like we already have are seeing there.

37
00:02:13,830 --> 00:02:17,160
And you can see we didn't have the size argument here.

38
00:02:17,520 --> 00:02:20,550
So now let's put in this size argument right now.

39
00:02:20,820 --> 00:02:23,400
But size equal to let's try six.

40
00:02:24,450 --> 00:02:27,630
And you can see it's going to be displayed much smaller than previously.

41
00:02:28,140 --> 00:02:29,280
The default is 10.

42
00:02:29,610 --> 00:02:34,770
So if you leave it out entirely, it uses 10 as the default in that function.

43
00:02:36,950 --> 00:02:37,760
So that's pretty cool.

44
00:02:38,090 --> 00:02:43,850
So now let's move on to Greece dealing damage, so it wasn't going to go ahead and preview that what

45
00:02:43,940 --> 00:02:48,740
images looks like, what I'm going to do actually might as well, because this could might be easier

46
00:02:48,740 --> 00:02:51,590
to see if it's in the middle of the screen for you guys.

47
00:02:52,130 --> 00:02:57,630
So what we do here, remember the key to this CVT dot?

48
00:02:57,710 --> 00:03:00,710
Sorry to see v2 dot CVD, the tea color function.

49
00:03:01,310 --> 00:03:05,400
Remember, we changed it from BGR to RGV in the function here.

50
00:03:06,800 --> 00:03:10,670
As you can see, CVT color, we couldn't fitting into BGR to RGV.

51
00:03:10,970 --> 00:03:13,760
What we're going to do now is convert it into gray.

52
00:03:14,180 --> 00:03:20,990
BGR to Gray is a lot of these built in conversions into different color spaces and is a lot of them

53
00:03:20,990 --> 00:03:21,970
built into open TV?

54
00:03:21,980 --> 00:03:24,860
You wouldn't need a lot of them unless you're doing something special.

55
00:03:25,280 --> 00:03:29,450
What we do is we do use a few of them in this course and you'll encounter them occasionally.

56
00:03:30,080 --> 00:03:35,870
So this color function, this basically just takes two arguments, as you saw previously the image,

57
00:03:36,050 --> 00:03:37,310
that's what we look at here.

58
00:03:37,730 --> 00:03:39,580
You can see it's easy to read.

59
00:03:39,980 --> 00:03:42,590
We've loaded this image and stored it as a variable here.

60
00:03:43,730 --> 00:03:50,900
And and now the other argument is basically the conversion code here.

61
00:03:51,680 --> 00:03:54,750
So we've called in this new image that created.

62
00:03:55,490 --> 00:03:57,020
We're calling it gray image.

63
00:03:57,620 --> 00:04:02,660
So now let's display gray image using our major function, and we give it a nice little title converted

64
00:04:02,660 --> 00:04:03,410
to grayscale.

65
00:04:04,400 --> 00:04:08,930
And we can see it looks a lot less pretty in black and white, but that's how it is.

66
00:04:08,930 --> 00:04:09,710
That's grayscale.

67
00:04:09,980 --> 00:04:11,930
Now what is grayscale actually mean?

68
00:04:11,930 --> 00:04:17,270
Do you remember RGV has true dimensions red, blue and green?

69
00:04:18,260 --> 00:04:21,470
Well, in grayscale is just one dimension.

70
00:04:21,920 --> 00:04:27,620
It's an intensity of gray or black, or that red color range between the white and black.

71
00:04:28,160 --> 00:04:35,690
So as you can see, let's assume in a bit here, you can see that this is the number one that was handwritten

72
00:04:35,690 --> 00:04:36,500
by me, actually.

73
00:04:37,100 --> 00:04:39,180
And you can see these are the color codes here.

74
00:04:39,200 --> 00:04:48,950
You can see two, when it's took 55 to 55 is the range of all colors and off into it, skill is zero

75
00:04:49,000 --> 00:04:49,850
to 255.

76
00:04:49,940 --> 00:04:51,140
Zero is black.

77
00:04:51,410 --> 00:04:53,810
You don't even see the zeros here because they're actually black as well.

78
00:04:54,380 --> 00:05:00,230
But the numbers zero, but at zero mean jurors absence of light.

79
00:05:00,440 --> 00:05:01,160
Totally black.

80
00:05:01,820 --> 00:05:04,280
However, white is the maximum color.

81
00:05:04,280 --> 00:05:09,110
That's 255 because that's orange 256 numbers zero to 255.

82
00:05:09,650 --> 00:05:12,410
So you can see 255 is pure white.

83
00:05:12,800 --> 00:05:17,120
And as you come down like 227, it's a lighter shade than 220.

84
00:05:17,510 --> 00:05:20,630
170 is darker and 90 you want is quite darker.

85
00:05:21,260 --> 00:05:23,070
68 is much darker.

86
00:05:23,090 --> 00:05:25,430
This one is probably 20 or 30.

87
00:05:26,270 --> 00:05:28,250
So you can see the colors there.

88
00:05:29,480 --> 00:05:30,860
So that's how grayscale.

89
00:05:31,880 --> 00:05:34,530
That's how we actually display grayscale images.

90
00:05:34,550 --> 00:05:38,630
It's just all these three dimensions here now compressed into one dimension.

91
00:05:38,720 --> 00:05:44,680
So to Grayscale, the image open TV takes the average of the red, green and blue colors, and this

92
00:05:44,690 --> 00:05:46,940
uses that as a final intensity here.

93
00:05:48,740 --> 00:05:50,690
So again, we get this through the shape.

94
00:05:50,690 --> 00:05:52,610
I don't know why I actually put this into the lesson.

95
00:05:53,240 --> 00:05:56,460
If you just wanted to see the shape, the ship is consistently to seem to agree.

96
00:05:56,460 --> 00:06:00,380
The scaling doesn't change, and that's it for this lesson.

97
00:06:00,590 --> 00:06:05,510
So in this lesson, we just learned a very simple way to just to convert an image to grayscale.

98
00:06:06,080 --> 00:06:10,370
Nothing too amazing, but it's actually a very handy function in OpenCV.

99
00:06:11,120 --> 00:06:16,340
And that's because a lot of other functions can only take grayscale images as inputs.

100
00:06:16,730 --> 00:06:24,590
So hopefully you found this important and and you take away a valuable lesson from this, this dissection.

101
00:06:25,190 --> 00:06:27,020
So now let's move on to the third section.

102
00:06:27,380 --> 00:06:28,220
So stay tuned.
