Java rotation of pixel array

后端 未结 2 1419
陌清茗
陌清茗 2020-12-18 12:55

I have tried to make an algorithm in java to rotate a 2-d pixel array(Not restricted to 90 degrees), the only problem i have with this is: the end result leaves me with dots

2条回答
  •  忘掉有多难
    2020-12-18 13:10

    You are pushing the pixels forward, and not every pixel is hit by the discretized rotation map. You can get rid of the gaps by calculating the source of each pixel instead.

    Instead of

    for each pixel p in the source
        pixel q = rotate(p, theta)
        q.setColor(p.getColor())
    

    try

    for each pixel q in the image
        pixel p = rotate(q, -theta)
        q.setColor(p.getColor())
    

    This will still have visual artifacts. You can improve on this by interpolating instead of rounding the coordinates of the source pixel p to integer values.


    Edit: Your rotation formulas looked odd, but they appear ok after using trig identities like cos(r+pi/2) = -sin(r) and sin(r+pi/2)=cos(r). They should not be the cause of any stretching.

提交回复
热议问题