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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Algorithm: Shadow Classification for Vehicle
2
+ Input:
3
+
4
+ A mask image of the vehicle (binary values of 0 and 255).
5
+ Four keypoints corresponding to the bottom-most points of the vehicle's tires: front-left, front-right, rear-left, rear-right. These are crucial for shadow generation.
6
+ Steps:
7
+ Step 1: Input and Preprocessing
8
+ Take the vehicle mask (M) as input, which is a binary matrix where each pixel has a value of 0 (background) or 255 (vehicle).
9
+ The four keypoints (K_fl, K_fr, K_rl, K_rr) are provided as pixel coordinates:
10
+ 𝐾
11
+ 𝑓
12
+ 𝑙
13
+ =
14
+ (
15
+ π‘₯
16
+ 𝑓
17
+ 𝑙
18
+ ,
19
+ 𝑦
20
+ 𝑓
21
+ 𝑙
22
+ )
23
+ K
24
+ fl
25
+ ​
26
+ =(x
27
+ fl
28
+ ​
29
+ ,y
30
+ fl
31
+ ​
32
+ )
33
+ 𝐾
34
+ π‘Ÿ
35
+ 𝑙
36
+ =
37
+ (
38
+ π‘₯
39
+ π‘Ÿ
40
+ 𝑙
41
+ ,
42
+ 𝑦
43
+ π‘Ÿ
44
+ 𝑙
45
+ )
46
+ K
47
+ rl
48
+ ​
49
+ =(x
50
+ rl
51
+ ​
52
+ ,y
53
+ rl
54
+ ​
55
+ )
56
+ Step 2: Calculate the Angle Between Keypoints
57
+ Use the front-left and rear-left keypoints to calculate the angle the vehicle makes with the x-axis:
58
+
59
+ πœƒ
60
+ =
61
+ tan
62
+ ⁑
63
+ βˆ’
64
+ 1
65
+ (
66
+ 𝑦
67
+ 𝑓
68
+ 𝑙
69
+ βˆ’
70
+ 𝑦
71
+ π‘Ÿ
72
+ 𝑙
73
+ π‘₯
74
+ 𝑓
75
+ 𝑙
76
+ βˆ’
77
+ π‘₯
78
+ π‘Ÿ
79
+ 𝑙
80
+ )
81
+ ΞΈ=tan
82
+ βˆ’1
83
+ (
84
+ x
85
+ fl
86
+ ​
87
+ βˆ’x
88
+ rl
89
+ ​
90
+
91
+ y
92
+ fl
93
+ ​
94
+ βˆ’y
95
+ rl
96
+ ​
97
+
98
+ ​
99
+ )
100
+ This gives the angle
101
+ πœƒ
102
+ ΞΈ in radians, which indicates how much the vehicle is inclined relative to the x-axis.
103
+ Step 3: Rotate the Mask
104
+ Rotate the mask M clockwise by angle
105
+ πœƒ
106
+ ΞΈ to align the vehicle along the x-axis. The rotation can be done using a rotation matrix or a simple image rotation function (e.g., using OpenCV's warpAffine).
107
+
108
+ Mathematically, each pixel's new coordinates after rotation:
109
+
110
+ (
111
+ π‘₯
112
+ β€²
113
+ 𝑦
114
+ β€²
115
+ )
116
+ =
117
+ (
118
+ cos
119
+ ⁑
120
+ (
121
+ πœƒ
122
+ )
123
+ sin
124
+ ⁑
125
+ (
126
+ πœƒ
127
+ )
128
+ βˆ’
129
+ sin
130
+ ⁑
131
+ (
132
+ πœƒ
133
+ )
134
+ cos
135
+ ⁑
136
+ (
137
+ πœƒ
138
+ )
139
+ )
140
+ (
141
+ π‘₯
142
+ 𝑦
143
+ )
144
+ (
145
+ x
146
+ β€²
147
+
148
+ y
149
+ β€²
150
+
151
+ ​
152
+ )=(
153
+ cos(ΞΈ)
154
+ βˆ’sin(ΞΈ)
155
+ ​
156
+
157
+ sin(ΞΈ)
158
+ cos(ΞΈ)
159
+ ​
160
+ )(
161
+ x
162
+ y
163
+ ​
164
+ )
165
+ Step 4: Recalculate Rear-left Keypoint
166
+ After the mask rotation, recalculate the new position of the rear-left keypoint. Apply the same rotation transformation to get the new coordinates:
167
+
168
+ 𝐾
169
+ π‘Ÿ
170
+ 𝑙
171
+ β€²
172
+ =
173
+ (
174
+ π‘₯
175
+ π‘Ÿ
176
+ 𝑙
177
+ β€²
178
+ ,
179
+ 𝑦
180
+ π‘Ÿ
181
+ 𝑙
182
+ β€²
183
+ )
184
+ K
185
+ rl
186
+ β€²
187
+ ​
188
+ =(x
189
+ rl
190
+ β€²
191
+ ​
192
+ ,y
193
+ rl
194
+ β€²
195
+ ​
196
+ )
197
+ Where:
198
+
199
+ π‘₯
200
+ π‘Ÿ
201
+ 𝑙
202
+ β€²
203
+ =
204
+ π‘₯
205
+ π‘Ÿ
206
+ 𝑙
207
+ cos
208
+ ⁑
209
+ (
210
+ πœƒ
211
+ )
212
+ βˆ’
213
+ 𝑦
214
+ π‘Ÿ
215
+ 𝑙
216
+ sin
217
+ ⁑
218
+ (
219
+ πœƒ
220
+ )
221
+ x
222
+ rl
223
+ β€²
224
+ ​
225
+ =x
226
+ rl
227
+ ​
228
+ cos(ΞΈ)βˆ’y
229
+ rl
230
+ ​
231
+ sin(ΞΈ)
232
+ 𝑦
233
+ π‘Ÿ
234
+ 𝑙
235
+ β€²
236
+ =
237
+ π‘₯
238
+ π‘Ÿ
239
+ 𝑙
240
+ sin
241
+ ⁑
242
+ (
243
+ πœƒ
244
+ )
245
+ +
246
+ 𝑦
247
+ π‘Ÿ
248
+ 𝑙
249
+ cos
250
+ ⁑
251
+ (
252
+ πœƒ
253
+ )
254
+ y
255
+ rl
256
+ β€²
257
+ ​
258
+ =x
259
+ rl
260
+ ​
261
+ sin(ΞΈ)+y
262
+ rl
263
+ ​
264
+ cos(ΞΈ)
265
+ Step 5: Crop the Mask
266
+ Center the cropped region around the new rear-left keypoint
267
+ 𝐾
268
+ π‘Ÿ
269
+ 𝑙
270
+ β€²
271
+ K
272
+ rl
273
+ β€²
274
+ ​
275
+ and crop a square of size
276
+ (
277
+ 𝑀
278
+ 𝑖
279
+ 𝑑
280
+ 𝑑
281
+ β„Ž
282
+ =
283
+ β„Ž
284
+ 𝑒
285
+ 𝑖
286
+ 𝑔
287
+ β„Ž
288
+ 𝑑
289
+ =
290
+ 100
291
+ Β pixels
292
+ )
293
+ (width=height=100Β pixels).
294
+
295
+ Crop dimensions:
296
+
297
+ π‘₯
298
+ π‘š
299
+ 𝑖
300
+ 𝑛
301
+ =
302
+ π‘₯
303
+ π‘Ÿ
304
+ 𝑙
305
+ β€²
306
+ βˆ’
307
+ 50
308
+ ,
309
+ π‘₯
310
+ π‘š
311
+ π‘Ž
312
+ π‘₯
313
+ =
314
+ π‘₯
315
+ π‘Ÿ
316
+ 𝑙
317
+ β€²
318
+ +
319
+ 50
320
+ x
321
+ min
322
+ ​
323
+ =x
324
+ rl
325
+ β€²
326
+ ​
327
+ βˆ’50,x
328
+ max
329
+ ​
330
+ =x
331
+ rl
332
+ β€²
333
+ ​
334
+ +50
335
+ 𝑦
336
+ π‘š
337
+ 𝑖
338
+ 𝑛
339
+ =
340
+ 𝑦
341
+ π‘Ÿ
342
+ 𝑙
343
+ β€²
344
+ βˆ’
345
+ 50
346
+ ,
347
+ 𝑦
348
+ π‘š
349
+ π‘Ž
350
+ π‘₯
351
+ =
352
+ 𝑦
353
+ π‘Ÿ
354
+ 𝑙
355
+ β€²
356
+ +
357
+ 50
358
+ y
359
+ min
360
+ ​
361
+ =y
362
+ rl
363
+ β€²
364
+ ​
365
+ βˆ’50,y
366
+ max
367
+ ​
368
+ =y
369
+ rl
370
+ β€²
371
+ ​
372
+ +50
373
+ Step 6: Find Bottom-most Point
374
+ In the cropped mask, identify the bottom-most point
375
+ 𝐡
376
+ =
377
+ (
378
+ π‘₯
379
+ 𝑏
380
+ ,
381
+ 𝑦
382
+ 𝑏
383
+ )
384
+ B=(x
385
+ b
386
+ ​
387
+ ,y
388
+ b
389
+ ​
390
+ ), where the pixel value is 255.
391
+
392
+ 𝑦
393
+ 𝑏
394
+ =
395
+ max
396
+ ⁑
397
+ {
398
+ 𝑦
399
+ ∣
400
+ 𝑀
401
+ (
402
+ π‘₯
403
+ ,
404
+ 𝑦
405
+ )
406
+ =
407
+ 255
408
+ }
409
+ y
410
+ b
411
+ ​
412
+ =max{y∣M(x,y)=255}
413
+ Step 7: Calculate Distance
414
+ Compute the Euclidean distance
415
+ 𝐷
416
+ D between the new rear-left keypoint
417
+ 𝐾
418
+ π‘Ÿ
419
+ 𝑙
420
+ β€²
421
+ K
422
+ rl
423
+ β€²
424
+ ​
425
+ and the bottom-most point
426
+ 𝐡
427
+ B:
428
+
429
+ 𝐷
430
+ =
431
+ (
432
+ π‘₯
433
+ π‘Ÿ
434
+ 𝑙
435
+ β€²
436
+ βˆ’
437
+ π‘₯
438
+ 𝑏
439
+ )
440
+ 2
441
+ +
442
+ (
443
+ 𝑦
444
+ π‘Ÿ
445
+ 𝑙
446
+ β€²
447
+ βˆ’
448
+ 𝑦
449
+ 𝑏
450
+ )
451
+ 2
452
+ D=
453
+ (x
454
+ rl
455
+ β€²
456
+ ​
457
+ βˆ’x
458
+ b
459
+ ​
460
+ )
461
+ 2
462
+ +(y
463
+ rl
464
+ β€²
465
+ ​
466
+ βˆ’y
467
+ b
468
+ ​
469
+ )
470
+ 2
471
+
472
+ ​
473
+
474
+ Step 8: Shadow Classification
475
+ If
476
+ 𝐷
477
+ >
478
+ 50
479
+ D>50 pixels, classify the shadow as bad (unrealistic or incorrect). Otherwise, classify the shadow as good.
480
+ Mathematical Justification:
481
+ Rotation is used to align the vehicle to the x-axis, ensuring that the keypoints are more easily analyzed.
482
+ The distance threshold of 50 pixels helps determine if the shadow is too far from the vehicle’s edge (indicating that it might be unrealistic).
483
+ This refined version adds mathematical clarity to each step and ensures the algorithm is robust in detecting unrealistic shadows.