1

I want to perform matrix transformation operations like rotation, scaling, translation on an image without any other external library(PIL, CV2) function call.

I am trying with the basic matrix transformation approach. But I am facing some issues likes while rotation there are holes, image is cropped.

I want to perform all the above operation by along the center. Needed some guidance here.

Rotation Logic:

newImage = np.zeros((2*row, 2*column, 3), dtype=np.uint8)
radAngle = math.radians(int(input("angle: ")))
c, s = math.cos(radAngle), math.sin(radAngle)
mid_coords = np.floor(0.5*np.array(image.shape))
for i in range(0, row-1):
    for j in range(0, column-1):
        x2 = mid_coords[0] + (i-mid_coords[0])*c - (j-mid_coords[1])*s
        y2 = mid_coords[1] + (i-mid_coords[0])*s + (j-mid_coords[1])*c 
        newImage[int(math.ceil(x2)), int(math.ceil(y2))] = image[i, j]
RollBack
  • 11
  • 1
  • Possible duplicate of [Image rotation by Matlab without using imrotate](https://stackoverflow.com/questions/19684617/image-rotation-by-matlab-without-using-imrotate) – Kishore Kumar Singh Sep 23 '19 at 11:52

1 Answers1

1

The reason for holes in your rotated image is you are assigning each pixel of your original image to the computed pixel location in the rotated image. Due to this, some pixels in the rotated image are left out. You should do the other way round. For each pixel in the rotated image, find its value from the original image. Please refer to this answer.