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|
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.
|