Algorithm: Shadow Classification for Vehicle Input: A mask image of the vehicle (binary values of 0 and 255). 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. Steps: Step 1: Input and Preprocessing Take the vehicle mask (M) as input, which is a binary matrix where each pixel has a value of 0 (background) or 255 (vehicle). The four keypoints (K_fl, K_fr, K_rl, K_rr) are provided as pixel coordinates: 𝐾 𝑓 𝑙 = ( π‘₯ 𝑓 𝑙 , 𝑦 𝑓 𝑙 ) K fl ​ =(x fl ​ ,y fl ​ ) 𝐾 π‘Ÿ 𝑙 = ( π‘₯ π‘Ÿ 𝑙 , 𝑦 π‘Ÿ 𝑙 ) K rl ​ =(x rl ​ ,y rl ​ ) Step 2: Calculate the Angle Between Keypoints Use the front-left and rear-left keypoints to calculate the angle the vehicle makes with the x-axis: πœƒ = tan ⁑ βˆ’ 1 ( 𝑦 𝑓 𝑙 βˆ’ 𝑦 π‘Ÿ 𝑙 π‘₯ 𝑓 𝑙 βˆ’ π‘₯ π‘Ÿ 𝑙 ) ΞΈ=tan βˆ’1 ( x fl ​ βˆ’x rl ​ y fl ​ βˆ’y rl ​ ​ ) This gives the angle πœƒ ΞΈ in radians, which indicates how much the vehicle is inclined relative to the x-axis. Step 3: Rotate the Mask Rotate the mask M clockwise by angle πœƒ ΞΈ 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). Mathematically, each pixel's new coordinates after rotation: ( π‘₯ β€² 𝑦 β€² ) = ( cos ⁑ ( πœƒ ) sin ⁑ ( πœƒ ) βˆ’ sin ⁑ ( πœƒ ) cos ⁑ ( πœƒ ) ) ( π‘₯ 𝑦 ) ( x β€² y β€² ​ )=( cos(ΞΈ) βˆ’sin(ΞΈ) ​ sin(ΞΈ) cos(ΞΈ) ​ )( x y ​ ) Step 4: Recalculate Rear-left Keypoint After the mask rotation, recalculate the new position of the rear-left keypoint. Apply the same rotation transformation to get the new coordinates: 𝐾 π‘Ÿ 𝑙 β€² = ( π‘₯ π‘Ÿ 𝑙 β€² , 𝑦 π‘Ÿ 𝑙 β€² ) K rl β€² ​ =(x rl β€² ​ ,y rl β€² ​ ) Where: π‘₯ π‘Ÿ 𝑙 β€² = π‘₯ π‘Ÿ 𝑙 cos ⁑ ( πœƒ ) βˆ’ 𝑦 π‘Ÿ 𝑙 sin ⁑ ( πœƒ ) x rl β€² ​ =x rl ​ cos(ΞΈ)βˆ’y rl ​ sin(ΞΈ) 𝑦 π‘Ÿ 𝑙 β€² = π‘₯ π‘Ÿ 𝑙 sin ⁑ ( πœƒ ) + 𝑦 π‘Ÿ 𝑙 cos ⁑ ( πœƒ ) y rl β€² ​ =x rl ​ sin(ΞΈ)+y rl ​ cos(ΞΈ) Step 5: Crop the Mask Center the cropped region around the new rear-left keypoint 𝐾 π‘Ÿ 𝑙 β€² K rl β€² ​ and crop a square of size ( 𝑀 𝑖 𝑑 𝑑 β„Ž = β„Ž 𝑒 𝑖 𝑔 β„Ž 𝑑 = 100 Β pixels ) (width=height=100Β pixels). Crop dimensions: π‘₯ π‘š 𝑖 𝑛 = π‘₯ π‘Ÿ 𝑙 β€² βˆ’ 50 , π‘₯ π‘š π‘Ž π‘₯ = π‘₯ π‘Ÿ 𝑙 β€² + 50 x min ​ =x rl β€² ​ βˆ’50,x max ​ =x rl β€² ​ +50 𝑦 π‘š 𝑖 𝑛 = 𝑦 π‘Ÿ 𝑙 β€² βˆ’ 50 , 𝑦 π‘š π‘Ž π‘₯ = 𝑦 π‘Ÿ 𝑙 β€² + 50 y min ​ =y rl β€² ​ βˆ’50,y max ​ =y rl β€² ​ +50 Step 6: Find Bottom-most Point In the cropped mask, identify the bottom-most point 𝐡 = ( π‘₯ 𝑏 , 𝑦 𝑏 ) B=(x b ​ ,y b ​ ), where the pixel value is 255. 𝑦 𝑏 = max ⁑ { 𝑦 ∣ 𝑀 ( π‘₯ , 𝑦 ) = 255 } y b ​ =max{y∣M(x,y)=255} Step 7: Calculate Distance Compute the Euclidean distance 𝐷 D between the new rear-left keypoint 𝐾 π‘Ÿ 𝑙 β€² K rl β€² ​ and the bottom-most point 𝐡 B: 𝐷 = ( π‘₯ π‘Ÿ 𝑙 β€² βˆ’ π‘₯ 𝑏 ) 2 + ( 𝑦 π‘Ÿ 𝑙 β€² βˆ’ 𝑦 𝑏 ) 2 D= (x rl β€² ​ βˆ’x b ​ ) 2 +(y rl β€² ​ βˆ’y b ​ ) 2 ​ Step 8: Shadow Classification If 𝐷 > 50 D>50 pixels, classify the shadow as bad (unrealistic or incorrect). Otherwise, classify the shadow as good. Mathematical Justification: Rotation is used to align the vehicle to the x-axis, ensuring that the keypoints are more easily analyzed. 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). This refined version adds mathematical clarity to each step and ensures the algorithm is robust in detecting unrealistic shadows.