1
00:00:00,480 --> 00:00:05,910
In my project directory, I have this images folder, which has six images.

2
00:00:07,440 --> 00:00:15,240
Now, in this lecture, we're going to write a script which gets all these images and it produces.

3
00:00:16,379 --> 00:00:25,920
This image collage, so all these six images are here in one single image, and we're going to generate

4
00:00:25,920 --> 00:00:27,630
this automatically with Python.

5
00:00:27,900 --> 00:00:29,700
You can see we have some genes.

6
00:00:31,080 --> 00:00:32,280
Around each image.

7
00:00:33,780 --> 00:00:34,780
So that's the ultimate.

8
00:00:35,070 --> 00:00:39,210
I'm going to delete the old footnote and recreate it again via Python.

9
00:00:39,870 --> 00:00:46,680
You can find all these six images attached in the lecture resources so that you can also work on the

10
00:00:46,680 --> 00:00:48,630
script using these images.

11
00:00:49,020 --> 00:00:57,600
So let's go to my main that if you to file an import open CV, so we're going to use open CV for this,

12
00:00:57,600 --> 00:01:01,140
which, as you know, can be imported as import quota.

13
00:01:02,220 --> 00:01:09,390
Then you want to define firsthand how many columns and rows the class will have.

14
00:01:09,960 --> 00:01:18,630
Since we have six images here, it makes sense to have something like three columns and two rows or

15
00:01:18,630 --> 00:01:20,160
two rows and three columns.

16
00:01:20,910 --> 00:01:27,450
You can also get this from the user using an input function so you can gather this data from the user.

17
00:01:27,460 --> 00:01:30,120
But let's keep it simple let's just write them here.

18
00:01:30,390 --> 00:01:32,340
We have a lot of other quotes, right?

19
00:01:32,820 --> 00:01:34,110
So let's keep this simple.

20
00:01:34,530 --> 00:01:43,890
And then you want to get a list of the image paths you want to use as input images, which are all these

21
00:01:43,890 --> 00:01:44,610
six images.

22
00:01:45,120 --> 00:01:51,120
So I'm going to just use always the two lists there and give the path to the folder.

23
00:01:52,080 --> 00:01:57,030
So if I print images now and of course, I need to import OS.

24
00:02:04,620 --> 00:02:08,850
That will give me a list of image file names, right?

25
00:02:08,940 --> 00:02:10,259
What else do we need?

26
00:02:11,160 --> 00:02:15,840
Well, you throw some more genes around each image.

27
00:02:16,560 --> 00:02:24,690
So if you want the user to also specify what the margin size is, you want to have a variable or maybe

28
00:02:24,690 --> 00:02:26,280
an input function for that too.

29
00:02:26,550 --> 00:02:31,050
So let's say horizontal merging.

30
00:02:32,400 --> 00:02:39,600
A sequel to four and the vertical merging is 20.

31
00:02:40,140 --> 00:02:41,730
So what are these?

32
00:02:41,880 --> 00:02:50,100
Well, if I show you the output image again, so with horizontal merging worlds, I'm trying to say,

33
00:02:50,100 --> 00:02:56,700
is this area here, this space wide space which lies horizontally?

34
00:02:57,480 --> 00:03:02,190
Of those who are vertical lines such as this and that are vertical merge.

35
00:03:03,450 --> 00:03:08,670
So that's where the big toe, the vertical one and 44, the horizontal one.

36
00:03:09,180 --> 00:03:11,100
So 40 pixels, 20 pixels.

37
00:03:12,540 --> 00:03:17,760
What other parameter should we define before we go to the processing part?

38
00:03:18,600 --> 00:03:24,630
Well, we should get to the values of the dimensions of these images.

39
00:03:24,900 --> 00:03:30,600
So for this scripts, it is required that all the images have the same dimensions.

40
00:03:31,350 --> 00:03:34,380
The algorithm that we built requires that.

41
00:03:34,620 --> 00:03:38,760
So that means all of these images should be the same resolution.

42
00:03:39,360 --> 00:03:44,910
And beforehand, we need to get the shape of those images.

43
00:03:45,210 --> 00:03:47,610
So the shape of one image is enough.

44
00:03:49,220 --> 00:03:59,250
To give the shape of an image, we need to use Siri to that I am Reed's immature read and then provide

45
00:03:59,270 --> 00:04:00,800
a path to the image.

46
00:04:01,190 --> 00:04:03,910
The path to the image is this.

47
00:04:04,580 --> 00:04:13,940
Plus the directory, so that would be images slash one that JPEG event.

48
00:04:13,940 --> 00:04:20,660
We want to access the shape out of that image object, which is a property, not a method.

49
00:04:21,290 --> 00:04:25,910
So that will give us the shape the shape is.

50
00:04:28,750 --> 00:04:37,930
This so that's the height, that's the width, and that's the image depth, so to see with that now

51
00:04:37,930 --> 00:04:41,280
we have all the parameters we want for the algorithm.

52
00:04:41,290 --> 00:04:46,480
So we have the number of columns, arrows for the image collage and the margin size.

53
00:04:47,650 --> 00:04:51,820
We have the path to the imposing images and we have the shape of those images.

54
00:04:52,120 --> 00:04:54,160
Let's start with the processing part now.

55
00:04:54,610 --> 00:04:56,350
How are we going to handle this?

56
00:04:57,100 --> 00:05:03,430
Well, for that, we will create some sort of an empty image, a wide image.

57
00:05:03,940 --> 00:05:06,970
To do that, we're going to need non-point.

58
00:05:07,450 --> 00:05:13,630
So important not, which allows you to create multidimensional arrays.

59
00:05:14,500 --> 00:05:17,860
So you know that an image has three dimensions.

60
00:05:18,190 --> 00:05:25,720
It has the height, the width and the depth, which defines the colors, the pixel values of the image.

61
00:05:26,170 --> 00:05:34,330
And so we need to create a name to image, which is basically this image here with this size.

62
00:05:35,050 --> 00:05:43,360
So the size of this image is going to be this merging here, plus the width of this image, plus the

63
00:05:43,360 --> 00:05:49,990
size of this vertical margin, plus the width of this image, plus the size of this plus the width of

64
00:05:49,990 --> 00:05:53,680
this plus the size of the vertical margin.

65
00:05:54,610 --> 00:05:57,400
So that is the white image.

66
00:05:57,400 --> 00:05:58,690
And then we'll add.

67
00:05:59,960 --> 00:06:03,530
Those images on top of the white image.

68
00:06:03,710 --> 00:06:05,690
So let's create that big image.

69
00:06:06,680 --> 00:06:07,070
No.

70
00:06:09,040 --> 00:06:14,050
Let's say big image, like that's a sequel to Non-Point Zeroes.

71
00:06:16,080 --> 00:06:19,820
Not by the zeros is the methods to create a non-player.

72
00:06:20,550 --> 00:06:23,610
And you can define how many dimensions you want.

73
00:06:24,180 --> 00:06:28,620
So we're going to start with the height of the image.

74
00:06:29,760 --> 00:06:34,680
Which is the number of pixels from here to there.

75
00:06:36,780 --> 00:06:38,220
How can we calculate that?

76
00:06:38,580 --> 00:06:49,200
Well, that'd be the height of one input image, which is shape zero, so that gives us the height of

77
00:06:49,200 --> 00:06:49,650
shape.

78
00:06:51,520 --> 00:07:02,650
Times Rose, so Rose is the number of rose we have, we have to, for example, so that means this hard

79
00:07:03,070 --> 00:07:06,880
times two gives us this height plus this height.

80
00:07:08,760 --> 00:07:17,520
But we need to also take into consideration the size of this margin, that's and that's one.

81
00:07:17,820 --> 00:07:24,930
So we're talking about three more genes or in other words, it is two.

82
00:07:25,500 --> 00:07:28,710
So the number of rows plus one.

83
00:07:29,190 --> 00:07:35,400
So if we have two rows as we have here, one here, two here, two rows of images, then we have three

84
00:07:36,060 --> 00:07:37,890
horizontal margins one two three.

85
00:07:38,130 --> 00:07:43,830
If we had three rows of images, we would have four more genes.

86
00:07:44,210 --> 00:07:45,360
So that's a formula.

87
00:07:46,200 --> 00:07:56,910
So in Python, that would be again the height times Theroux's glass horizontal margin times.

88
00:07:56,910 --> 00:08:01,050
We we said we have one to three.

89
00:08:01,090 --> 00:08:05,340
So three, which means two rows plus one.

90
00:08:06,150 --> 00:08:08,880
So times rows plus one.

91
00:08:09,150 --> 00:08:10,530
So that gives us three.

92
00:08:10,530 --> 00:08:15,900
In our case, because the rule is two, if Rose was three, we would have four margins and so on.

93
00:08:16,650 --> 00:08:19,440
So that's the first dimension of the big image.

94
00:08:24,800 --> 00:08:27,830
So it was this dimensional that we have calculated.

95
00:08:28,010 --> 00:08:31,610
Now let's calculate, let's find the formula of this dimension.

96
00:08:33,590 --> 00:08:37,549
Which is the width of one image.

97
00:08:37,880 --> 00:08:39,049
Times three.

98
00:08:39,980 --> 00:08:50,030
So we have three widths, plus we have one to three for a vertical margins.

99
00:08:50,270 --> 00:08:57,860
So it's basically the same formula, but this time we're going to work on shape one, which gives us

100
00:08:57,860 --> 00:08:59,210
the width of the image.

101
00:08:59,720 --> 00:09:05,210
Times columns plus vertical margin times.

102
00:09:06,110 --> 00:09:09,140
Columns plus one.

103
00:09:10,560 --> 00:09:19,590
And we also need the third dimension of the image, which is simply shape to which basically these three.

104
00:09:19,950 --> 00:09:28,050
So we have an image with three bands for the input images, and we're also going to have the same number

105
00:09:28,050 --> 00:09:32,550
of bands so blue, green and red for the output image.

106
00:09:33,570 --> 00:09:36,660
Now let's be a bit careful here.

107
00:09:37,250 --> 00:09:41,550
This 9.00 gets two arguments.

108
00:09:41,550 --> 00:09:48,480
Actually, the first argument is the dimensions, so we are going to put a bracket there and another

109
00:09:48,480 --> 00:09:49,410
brackets in here.

110
00:09:49,770 --> 00:09:51,390
So that is the first argument.

111
00:09:52,240 --> 00:09:54,060
This to put from there to here.

112
00:09:55,140 --> 00:10:02,940
That table had these one, two and three items, right?

113
00:10:03,630 --> 00:10:08,520
But that's typical is one single argument of the zero method.

114
00:10:08,760 --> 00:10:13,850
And the second argument is non-point, don't you?

115
00:10:13,860 --> 00:10:20,430
And eight, so that's the format or for the numbers of the array and then you close this.

116
00:10:20,910 --> 00:10:30,290
So actually, we should leave this parentheses so that the parentheses of this and that's all the parentheses

117
00:10:30,290 --> 00:10:31,350
is close in here.

118
00:10:32,610 --> 00:10:33,600
That's the image.

119
00:10:33,880 --> 00:10:41,550
Now if you write this image using an image, right methods and you specify.

120
00:10:43,000 --> 00:10:51,610
A path such as greed, JPEG and the actual image object, which is a big image, and then you run the

121
00:10:51,610 --> 00:10:52,030
script.

122
00:10:54,160 --> 00:10:58,960
Greet the Jeep pack is going to be a black image.

123
00:11:00,300 --> 00:11:09,630
It is still an image, but it has zeros as values, as pixel values for the three channels blue, green

124
00:11:09,630 --> 00:11:10,350
and red.

125
00:11:10,560 --> 00:11:11,520
So when you have.

126
00:11:13,230 --> 00:11:20,040
So when you have a zero value for blue and zero for green and zero for red, the combination of these

127
00:11:20,040 --> 00:11:22,740
three zeros gives you black color.

128
00:11:22,980 --> 00:11:31,980
If these were 255, 255 255, we would have white and anything between gives different combinations

129
00:11:31,980 --> 00:11:32,850
of colors.

130
00:11:33,840 --> 00:11:38,640
So for now, we have a big image, but we have the correct sizes I see.

131
00:11:39,960 --> 00:11:42,660
Now we need to add our images to this image.

132
00:11:43,260 --> 00:11:52,440
But just in case you want to make the image white, you can do that's using the field methods and you

133
00:11:52,440 --> 00:11:58,050
just provide 255, so events will replace all the zeros you run the script again.

134
00:11:58,410 --> 00:12:00,150
You see, now it's wide.

135
00:12:01,740 --> 00:12:02,040
So.

136
00:12:03,260 --> 00:12:08,090
Now we are ready to ask the actual six images to have this big image.

137
00:12:09,310 --> 00:12:17,890
Before we add those images, we need to have a list of coordinates where the corner of each image will

138
00:12:18,640 --> 00:12:19,360
be place.

139
00:12:19,540 --> 00:12:25,600
What I mean is each of these images is referenced by its upper left corner.

140
00:12:25,990 --> 00:12:32,440
So this corner here has a coordinates, which is, for example, for this one.

141
00:12:32,830 --> 00:12:36,250
It should be something like 40 20.

142
00:12:36,470 --> 00:12:44,650
So 40 is the number of pixels from this border here, and 20 is the number of pixels from that vertical

143
00:12:44,650 --> 00:12:45,040
border.

144
00:12:45,370 --> 00:12:55,210
So for the 24, that and then we have something like seven hundred sixty five, seven hundred sixty

145
00:12:55,240 --> 00:13:02,320
eight plus that's twenty here, plus another 20.

146
00:13:02,500 --> 00:13:06,190
So we're going to have a different value at different coordinates for the other image.

147
00:13:06,430 --> 00:13:13,990
And so one, how can we calculate these coordinates so that we can place each image in those coordinates?

148
00:13:15,060 --> 00:13:21,540
For this, I'm going to first calculate the great positions of each image.

149
00:13:21,990 --> 00:13:23,340
What do I mean by that?

150
00:13:26,070 --> 00:13:29,310
You'll see how this list will look like.

151
00:13:29,880 --> 00:13:36,420
So I'm going to do X Y to pull for X in range.

152
00:13:39,770 --> 00:13:51,980
Columns for Y in range rose and print out positions so that you can seat and I can explain to you what

153
00:13:51,980 --> 00:13:52,580
this is.

154
00:13:55,870 --> 00:13:57,520
That's the output that we got.

155
00:13:59,200 --> 00:14:02,170
So we have a list of two polls.

156
00:14:02,290 --> 00:14:05,050
Zero zero zero one one zero.

157
00:14:05,140 --> 00:14:10,840
So zero is the X here and the other zero is the Y.

158
00:14:11,440 --> 00:14:20,890
So we built a list comprehension and we construct X and y axis extracted from range columns, which

159
00:14:20,890 --> 00:14:24,670
basically gives us columns is three.

160
00:14:24,790 --> 00:14:27,940
So we get a range from zero to three.

161
00:14:29,200 --> 00:14:33,760
So when you iterate through that range for I in range three.

162
00:14:36,910 --> 00:14:39,040
I will be all the elements.

163
00:14:39,250 --> 00:14:40,510
Zero, one, two three.

164
00:14:41,020 --> 00:14:44,710
So these are the positions of each image in the greens.

165
00:14:44,980 --> 00:14:46,390
Zero zero means.

166
00:14:47,580 --> 00:14:52,320
This image, so in the room with index zero and column with index zero.

167
00:14:52,530 --> 00:14:59,760
And then we have the other images zero one again, the Rothe Index zero, but column with index one.

168
00:15:01,710 --> 00:15:02,310
And so on.

169
00:15:02,490 --> 00:15:19,260
Now, once we have that physicians list, we can iterate for Post X, Force Y and Z positions and images.

170
00:15:20,250 --> 00:15:24,930
So we have one two three four five six positions and six images.

171
00:15:24,930 --> 00:15:27,420
Images comes from this list here.

172
00:15:30,030 --> 00:15:36,960
So that zero zero will be the position of image one zero one will be the position of image two and so

173
00:15:36,960 --> 00:15:37,140
on.

174
00:15:37,890 --> 00:15:40,500
Now what can we do with this post and post?

175
00:15:40,540 --> 00:15:40,980
Why?

176
00:15:42,700 --> 00:15:52,390
Well, from that, we can derive the actual coordinates X and Y, so X would be force x times.

177
00:15:53,080 --> 00:16:04,930
Image width, which is shape zero plus the vertical margin because when we were working on the x axis,

178
00:16:05,410 --> 00:16:07,100
so we're calculating width.

179
00:16:07,520 --> 00:16:12,160
Plus this is a vertical machine, so width plus the vertical margin.

180
00:16:14,000 --> 00:16:16,160
Plus, another vertical merging.

181
00:16:16,760 --> 00:16:18,590
So why is that formula?

182
00:16:18,680 --> 00:16:22,640
Well, let's say the position is one.

183
00:16:22,790 --> 00:16:27,530
So for this image now the coordinates.

184
00:16:27,560 --> 00:16:32,760
What we're trying to calculate with is this coordinate this corner here.

185
00:16:33,500 --> 00:16:34,550
That's one in there.

186
00:16:34,760 --> 00:16:39,650
So that corner is one times.

187
00:16:41,130 --> 00:16:43,590
The width of an image.

188
00:16:45,570 --> 00:16:47,250
Plus the vertical merging.

189
00:16:50,220 --> 00:16:54,750
So the width plus the vertical margin takes us to this point.

190
00:16:55,950 --> 00:17:01,710
Now I'm adding another vertical margin because we have this initial margin here.

191
00:17:02,550 --> 00:17:08,700
So that means again, the position of this is that's an initial vertical margin plus the width loss

192
00:17:08,700 --> 00:17:09,750
and all the vertical margin.

193
00:17:09,990 --> 00:17:11,730
That's the formula here.

194
00:17:14,540 --> 00:17:23,060
And for what is going to be the same sort of post-WWII times shape to one in this case, plus horizontal

195
00:17:24,829 --> 00:17:25,310
gene.

196
00:17:28,329 --> 00:17:39,700
Plus, another horizontal margin, once we have these two X and Y values, then we can access the big

197
00:17:39,700 --> 00:17:46,360
image array and then mutate that array.

198
00:17:46,630 --> 00:17:51,520
So we are seeing that from Y OP to Y Plus.

199
00:17:54,500 --> 00:17:58,220
The Heights, which is one.

200
00:17:59,940 --> 00:18:03,360
And from X up to X Plus.

201
00:18:04,800 --> 00:18:16,260
The width, so we that's what we're accessing is, for example, this portion here and the next portion

202
00:18:16,260 --> 00:18:20,610
in the next iteration of the Loop and so soon.

203
00:18:21,030 --> 00:18:28,830
So in the first portion, we see that portion of the image will be equal to that image.

204
00:18:29,310 --> 00:18:30,390
So what is the image?

205
00:18:30,420 --> 00:18:33,870
Well, this actually should be in parentheses.

206
00:18:34,740 --> 00:18:38,580
So we're accessing the tips of the positions of that list.

207
00:18:38,970 --> 00:18:44,490
And we also access the image of that list.

208
00:18:45,390 --> 00:18:46,890
Actually, this is just the path.

209
00:18:47,250 --> 00:18:51,480
What we need to do is create a list of image objects.

210
00:18:52,170 --> 00:19:01,560
So image objects are actually a list comprehension which could be subject to the time reads.

211
00:19:02,130 --> 00:19:05,670
So we want to read images.

212
00:19:07,810 --> 00:19:18,520
Let's say a file name here for file name and images, so that will create a list of actual image objects

213
00:19:18,520 --> 00:19:20,050
and notes image paths.

214
00:19:20,380 --> 00:19:22,450
This outputs an image object.

215
00:19:22,930 --> 00:19:24,850
It needs a bracket in here.

216
00:19:25,480 --> 00:19:30,840
And also the f string in here because this is a variable and remove that parentheses.

217
00:19:31,030 --> 00:19:36,880
So that's a final list comprehension to create a list of image objects.

218
00:19:37,940 --> 00:19:47,480
Therefore, images should be replaced with image objects, and so image we go from there to here and

219
00:19:47,480 --> 00:19:54,440
be written in that slice of the big image that should do it.

220
00:19:54,440 --> 00:19:55,790
So I'm going to run the script.

221
00:19:58,010 --> 00:20:03,980
That error occurred because we have swept the heights with the width, actually so.

222
00:20:05,380 --> 00:20:12,550
So this year should be the height, but shape one gives us the width, actually, because this shape

223
00:20:13,120 --> 00:20:20,470
sequence, when we get it from here, it is a sequence of height and which saw the height is the first

224
00:20:20,470 --> 00:20:20,640
one.

225
00:20:20,650 --> 00:20:25,360
Therefore, we need the height here, so we need to place zero and one for this.

226
00:20:25,990 --> 00:20:28,820
The same goes for this formula here.

227
00:20:28,840 --> 00:20:32,170
So one there and zero there and run again.

228
00:20:35,260 --> 00:20:35,980
No error.

229
00:20:36,910 --> 00:20:39,130
Let's check greed, JPEG.

230
00:20:40,520 --> 00:20:41,450
Yeah, looks good.

231
00:20:42,800 --> 00:20:46,910
So the horizontal margin is greater than vertical merging.

232
00:20:47,270 --> 00:20:48,170
Let's check.

233
00:20:48,740 --> 00:20:48,980
Yeah.

234
00:20:49,400 --> 00:20:50,490
40 20.

235
00:20:50,510 --> 00:20:52,370
That makes sense.

236
00:20:53,540 --> 00:20:54,800
And that's the final output.

237
00:20:56,060 --> 00:20:56,930
So that's a code.

238
00:20:58,460 --> 00:21:02,390
So thanks a lot for following this video, and let's keep on learning.

