0

The answer asked in this assignment is the following: Rotate the image around its center (that is the point of coordinates (100,100)) of an angle theta sampled uniformly in the range [10, 80].

I tried to implement my function my function, but if i try to rotate the image my image to be rotated I find a wrong result and I can't find where's the error. For example, if I try to rotate the image of 180 degrees (only to understand if it works) and I always get the wrong result. wrong resul Another problem is that when I call the function the brightness of each small square inside the image is attenuate, why? Thanks to all

1
  • 2
    You have included neither your code, nor your data. Code cannot be executed from an image, and a plot of your input will not achieve the same results as your actual input. Commented Dec 20, 2022 at 15:53

1 Answer 1

0

I guess you must want to understand the image rotation implementation method, so you can refer to the link below for the implementation method: image affine: rotate

Code snippet:

# affine
def affine(img, a, b, c, d, tx, ty):
    H, W, C = _img.shape

    # temporary image
    img = np.zeros((H+2, W+2, C), dtype=np.float32)
    img[1:H+1, 1:W+1] = _img

    # get shape of new image
    H_new = np.round(H).astype(np.int)
    W_new = np.round(W).astype(np.int)
    out = np.zeros((H_new, W_new, C), dtype=np.float32)

    # get position of new image
    x_new = np.tile(np.arange(W_new), (H_new, 1))
    y_new = np.arange(H_new).repeat(W_new).reshape(H_new, -1)

    # get position of original image by affine
    adbc = a * d - b * c
    x = np.round((d * x_new  - b * y_new) / adbc).astype(np.int) - tx + 1
    y = np.round((-c * x_new + a * y_new) / adbc).astype(np.int) - ty + 1

    # adjust center by affine
    dcx = (x.max() + x.min()) // 2 - W // 2
    dcy = (y.max() + y.min()) // 2 - H // 2

    x -= dcx
    y -= dcy

    x = np.clip(x, 0, W + 1)
    y = np.clip(y, 0, H + 1)

    # assign pixcel
    out[y_new, x_new] = img[y, x]
    out = out.astype(np.uint8)

    return out

I didn't answer your question directly, but maybe you can find the answer in the code above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.