1
00:00:00,390 --> 00:00:06,750
In this video, we will add this watermark image to this image.

2
00:00:07,410 --> 00:00:10,320
The outputs will be this one here.

3
00:00:10,770 --> 00:00:17,220
You see that watermark has been added to this image and it's somewhat transparent.

4
00:00:18,300 --> 00:00:23,830
So let's delete this output and try to reproduce that output again.

5
00:00:25,030 --> 00:00:32,409
Using Python for this again, we will use Siri to solve the open C v library and.

6
00:00:35,460 --> 00:00:39,000
The first lines of codes will be the ones which.

7
00:00:40,770 --> 00:00:51,540
Load this these pack image and this page are images as open, see the image objects to cope events and

8
00:00:51,540 --> 00:00:53,070
repeat this year and see.

9
00:00:54,360 --> 00:00:56,910
Well, to Mark, though, it's punchy.

10
00:01:00,270 --> 00:01:03,840
So loads the two images.

11
00:01:05,650 --> 00:01:06,670
That's the first step.

12
00:01:08,670 --> 00:01:13,170
Then the next step, how do we want to approach this problem?

13
00:01:13,440 --> 00:01:20,280
So we have this image and we have that image, and we want to place this image somewhere here near the

14
00:01:20,280 --> 00:01:23,700
corner, actually exactly of the corner.

15
00:01:24,450 --> 00:01:33,540
And the way we're going to do this is by using an open of method called at weighted, which basically

16
00:01:33,540 --> 00:01:35,610
blends two images together.

17
00:01:35,670 --> 00:01:39,390
So we want to blend that this watermark with this image.

18
00:01:40,170 --> 00:01:46,140
So we want to specify where in this image the watermark will go.

19
00:01:46,170 --> 00:01:54,240
So we said somewhere here, therefore, we need to calculate now the coordinates of this point somewhere

20
00:01:54,240 --> 00:01:55,110
in here.

21
00:01:55,890 --> 00:02:05,250
But what you should know first is that the coordinate system often image has its origin in the upper

22
00:02:05,250 --> 00:02:07,500
left corner exactly here.

23
00:02:08,009 --> 00:02:09,870
So that's the zero zero points.

24
00:02:10,440 --> 00:02:13,110
So that is zero zero.

25
00:02:13,710 --> 00:02:16,920
Now what is the coordinate of this point here?

26
00:02:17,280 --> 00:02:22,410
Well, that would be something like 500 zero.

27
00:02:22,740 --> 00:02:23,310
Why?

28
00:02:23,340 --> 00:02:28,200
Because along the X, we suppose that this is around 500, right?

29
00:02:28,230 --> 00:02:31,890
Let's assume this width is five hundreds.

30
00:02:32,310 --> 00:02:36,960
Therefore, the value of the x axis in here will be around 500.

31
00:02:37,350 --> 00:02:41,760
So this on here and in this direction we've done, we didn't move.

32
00:02:41,790 --> 00:02:42,810
So that's why.

33
00:02:43,110 --> 00:02:45,060
Why is this zero?

34
00:02:45,360 --> 00:02:48,840
And then what would we have done here at this point?

35
00:02:49,140 --> 00:02:56,940
Well, that would be something like five hundred for X, and let's say a thousand for Y.

36
00:02:57,450 --> 00:03:04,500
So we went 500 to the right sides and it's a thousand down, right?

37
00:03:04,620 --> 00:03:07,410
So what is the coordinate of this point then?

38
00:03:07,650 --> 00:03:15,390
Well, since we will have that other image watermark, which has a shape like this, right?

39
00:03:15,780 --> 00:03:19,080
Then the coordinate here is five phones.

40
00:03:19,140 --> 00:03:23,960
It's minus, let's say this image is 100.

41
00:03:24,270 --> 00:03:26,490
So it would be five hundred minus 100.

42
00:03:27,030 --> 00:03:28,350
So that's the first coordinate.

43
00:03:28,350 --> 00:03:35,490
The second coordinate would be, let's say, a thousand thousand minus.

44
00:03:36,060 --> 00:03:38,780
Let's say this is thirty three.

45
00:03:39,240 --> 00:03:42,390
So with that, we have the two coordinates for this.

46
00:03:43,170 --> 00:03:55,660
So five hundred minus 100 takes us in here and 1000 minus 30 takes us in this point.

47
00:03:55,660 --> 00:03:57,930
So that's the formula, right?

48
00:03:58,620 --> 00:04:03,540
So let's go back to the code and calculate those coordinates.

49
00:04:05,010 --> 00:04:09,450
But for that, we need access to image that shape.

50
00:04:09,720 --> 00:04:18,810
So that's we'll print out sort of image image that shape to get the shapes of the dimensions of the

51
00:04:18,810 --> 00:04:23,070
image because those numbers that I was talking about were pixels.

52
00:04:23,580 --> 00:04:24,030
Right?

53
00:04:25,020 --> 00:04:28,620
So each pixel is one units in the coordinate system.

54
00:04:28,800 --> 00:04:35,760
Therefore, fifty two to ninety seven is a about.

55
00:04:37,120 --> 00:04:40,630
This watermark image, actually, I named them the same.

56
00:04:40,840 --> 00:04:46,450
So let's say water mark for this and say water mark here.

57
00:04:46,840 --> 00:04:47,260
Right?

58
00:04:48,370 --> 00:04:51,250
So 50 to 297.

59
00:04:52,350 --> 00:05:04,700
Fifty two is the height and 297 is the width, so we see that shape has why as the first axis.

60
00:05:05,670 --> 00:05:15,060
Therefore, what we want to do here is say X equals two image one.

61
00:05:15,300 --> 00:05:24,300
So we get to 97, actually, we get first, we get the X of the big image and then we're minus that

62
00:05:24,300 --> 00:05:26,790
with the X of the other image.

63
00:05:27,780 --> 00:05:36,630
So we would have image the shape one minus watermark, the shape one.

64
00:05:36,870 --> 00:05:38,760
So what is the image that shape one?

65
00:05:38,910 --> 00:05:40,800
And what is watermark the shape one?

66
00:05:40,950 --> 00:05:43,080
Well, this is that's one.

67
00:05:43,260 --> 00:05:46,470
It's because whatever that shape gives us this one.

68
00:05:46,860 --> 00:05:51,540
And the item within the X1 is 297, right?

69
00:05:52,110 --> 00:05:54,720
And the same goes for the main image.

70
00:05:55,200 --> 00:05:59,980
So basically now what we're doing is we are applying this formula.

71
00:06:00,000 --> 00:06:03,510
So five hundred the x of the main image.

72
00:06:03,870 --> 00:06:10,350
So this one here minus 100, the X or the watermark image?

73
00:06:10,500 --> 00:06:11,220
This one in here.

74
00:06:11,490 --> 00:06:18,060
So if we print this out, we get two one eight two three and we do the same for Y.

75
00:06:18,070 --> 00:06:20,760
So let's copy that here.

76
00:06:20,760 --> 00:06:24,240
And we say zero there, zero here.

77
00:06:24,240 --> 00:06:34,350
And this is why right now, what we can do is we can create a new variable, let's say, watermark portion

78
00:06:34,740 --> 00:06:35,790
or watermark.

79
00:06:35,790 --> 00:06:38,450
Place whatever you like to call it.

80
00:06:38,820 --> 00:06:40,260
This is B image.

81
00:06:41,410 --> 00:06:42,070
Why?

82
00:06:42,670 --> 00:06:46,180
I'll explain what I'm doing in just the bits of that.

83
00:06:46,480 --> 00:06:50,050
And if I say sorry to those, I'm right.

84
00:06:50,050 --> 00:06:56,140
So I create an image file with a name such as Watermark Place.

85
00:06:56,950 --> 00:07:03,940
That's Jake Tag using this watermark place, image, object and error on this.

86
00:07:05,230 --> 00:07:09,160
An image is generated a file and we open that.

87
00:07:09,640 --> 00:07:10,660
And this is what we see.

88
00:07:10,670 --> 00:07:11,740
So what is this?

89
00:07:12,130 --> 00:07:16,930
Well, this is this portion here, somewhere in here.

90
00:07:18,470 --> 00:07:27,530
So what we did is we extracted two we we created a new image out of this portion here and now we can

91
00:07:27,800 --> 00:07:38,780
blend, we can use this piece of image to blend it with our watermark because if you check the shape

92
00:07:38,780 --> 00:07:41,480
of this watermark, place the image.

93
00:07:42,080 --> 00:07:46,820
You're going to get the same dimensions as this watermark image.

94
00:07:47,120 --> 00:07:48,830
So they have the same dimensions now.

95
00:07:48,950 --> 00:07:59,090
Therefore, we can go ahead and apply the ads weighted methods, which will get as argument the first

96
00:07:59,090 --> 00:07:59,710
source.

97
00:07:59,710 --> 00:08:12,050
So you see S or C one the alpha and as our C two, so as our C one would be watermark place.

98
00:08:12,680 --> 00:08:13,940
Then we have the alpha.

99
00:08:15,230 --> 00:08:21,800
So Alpha is the first to wait for the first image in this case, the watermark, please.

100
00:08:22,070 --> 00:08:28,760
So we are blending two images and the outputs now is somehow a mixture between both.

101
00:08:29,030 --> 00:08:33,530
So you want to specify which of them you want to put more weight.

102
00:08:33,799 --> 00:08:34,880
We want a mixture.

103
00:08:34,890 --> 00:08:38,380
So let's say 0.5 for all four.

104
00:08:38,390 --> 00:08:44,450
And then we have the source number two, which is the watermark.

105
00:08:44,780 --> 00:08:49,790
So we are blending the watermark this one with.

106
00:08:50,810 --> 00:08:57,980
This rights, therefore, the watermark also needs a wait, let's for the same, and we also need to

107
00:08:58,460 --> 00:08:59,540
set a gum.

108
00:08:59,870 --> 00:09:05,510
Gum is now a value which can be added to all the pixels.

109
00:09:06,110 --> 00:09:10,460
We don't want any additional value to add to be added to the value of pixels.

110
00:09:10,700 --> 00:09:12,500
So I'm going to add zero here, right?

111
00:09:12,770 --> 00:09:15,050
So this will create a new image.

112
00:09:15,380 --> 00:09:21,470
Therefore, I'm going to assign this thing to a variable and then demonstrate you will.

113
00:09:21,470 --> 00:09:23,330
This variable is all about.

114
00:09:23,670 --> 00:09:28,490
So too does I'm right blend.

115
00:09:28,490 --> 00:09:34,280
That JPEG blend is image, object and run.

116
00:09:35,380 --> 00:09:40,660
So bland that dodgy pack now is the mixture between the two images.

117
00:09:41,620 --> 00:09:46,360
So you can play around with these values if you like, but I'm just going to leave them as they are

118
00:09:46,360 --> 00:09:49,710
and carry on with putting this balance.

119
00:09:49,720 --> 00:09:53,080
Now back to the image, that's very easy to do.

120
00:09:53,770 --> 00:10:02,110
You just referred to the portion of the image you want to change, which is that so what is this anyway?

121
00:10:02,740 --> 00:10:05,200
So image is this one right?

122
00:10:05,230 --> 00:10:07,690
ALFs, the JPEG, which is this one here?

123
00:10:08,200 --> 00:10:13,990
Now we are doing why and this column and that means.

124
00:10:15,130 --> 00:10:25,840
All the pixels of this image from the Y value, which is somewhere here, so we are extracting this

125
00:10:25,840 --> 00:10:33,880
portion and then we have also X, so from X and to the right.

126
00:10:35,280 --> 00:10:38,340
So X is somewhere in here.

127
00:10:39,120 --> 00:10:39,510
Right?

128
00:10:40,080 --> 00:10:46,530
So from there and down from here and down, and what we get is basically this area here.

129
00:10:46,860 --> 00:10:56,610
So now this area, we want to change it with blend, so that area will be equal to blend this image.

130
00:10:57,360 --> 00:11:01,440
In other words, this area will be replaced by that image and.

131
00:11:02,570 --> 00:11:04,030
CV two dots.

132
00:11:04,670 --> 00:11:10,640
I'm right, elf's watermarked, but Peg.

133
00:11:11,800 --> 00:11:13,600
And this is image.

134
00:11:14,350 --> 00:11:16,450
So this one in here, this one.

135
00:11:16,630 --> 00:11:20,980
But of course, this image has been changed at this point.

136
00:11:22,040 --> 00:11:28,040
So it's a mutable object, this image, and therefore you can change it like this.

137
00:11:29,540 --> 00:11:31,040
So if I run now.

138
00:11:32,560 --> 00:11:39,610
And check elf's watermarked, we see that the watermark has been successfully placed in the image,

139
00:11:40,480 --> 00:11:41,980
and that's the final code.

140
00:11:42,850 --> 00:11:48,880
I think this was an important exercise for you because it was an opportunity to understand the coordinate

141
00:11:48,880 --> 00:11:55,660
system of images and by knowing how the coordinate system works, you can do different manipulations

142
00:11:55,930 --> 00:11:56,890
on your image.

143
00:11:56,890 --> 00:12:01,450
Maybe you can add another layer on another image, like an entire layer.

144
00:12:01,840 --> 00:12:07,780
In this case, we'd just add it's something a layer in a particular portion of the image.

145
00:12:08,500 --> 00:12:09,190
So just you.

146
00:12:09,190 --> 00:12:16,540
But you can add something to our image to layer the transparent layer to an entire image by playing

147
00:12:16,540 --> 00:12:18,730
around with these numbers.

148
00:12:19,030 --> 00:12:20,350
The weights of each image.

149
00:12:20,800 --> 00:12:22,870
So thanks a lot, and I'll talk to you later.

