Skip to main content
. 2023 Sep 30;23(19):8190. doi: 10.3390/s23198190
Algorithm 2: Image random rotation enhancement algorithm
Input: image max_angle
Output: enhanced_image
  1:  function random_rotation(image, max_angle)
  2:  height, width = image.shape
  3:  Randomly generate the rotation angle. Randomly generated rotation angle θ can be represented by the random number function rand:
θ=rand×2×max¯anglemax¯angle
  4:  Calculate the center of rotation. Assume that the coordinates of the center of rotation are (x_center,y_center).
center_x=width2,center_y=height2
  5:  Define the rotation matrix.
rotation_matrix=cos(θ)sin(θ)(1cos(θ))·center_x+sin(θ)·centesin(θ)cos(θ)sin(θ)·center_x+(1cos(θ))·cent001
  6:  Performs image rotation. The position of each pixel after rotation is (x,y).
(x,y)=x=(xcenter_x)·cos(θ)(ycenter_y)·sin(θ)+center_xy=(xcenter_x)·sin(θ)+(ycenter_y)·cos(θ)+center_y
  7:  return rotated_image
  8:  end function