Your question is Image Rotation Coding. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Tesla Tecnologia e Comunicação's computer vision pipeline receives grayscale images that must be rotated before downstream processing. Implement a function that rotates an image counterclockwise by an arbitrary angle and returns the smallest rectangular output canvas containing the rotated image.
Use inverse mapping with nearest-neighbor sampling. Treat each pixel as a unit square centered at integer coordinates. Pixels in the output whose mapped source coordinate falls outside the input image must be filled with 0.
The input image is a non-empty rectangular 2D list of integers, where image[y][x] is the pixel at column x and row y. The input angle is measured in degrees and may be positive, negative, or greater than 360. Return a new 2D list of integers.
Rotate around the center of the input image. The output dimensions are:
ceil(width * |cos(angle)| + height * |sin(angle)|) columnsceil(width * |sin(angle)| + height * |cos(angle)|) rowsFor every output pixel, map its center backward through the inverse rotation. Round each source coordinate to the nearest integer, and copy that pixel when it is in bounds.
def rotate_image(image, angle):