title: Rotating 2D grayscale image with transformation matrix
body: <p>I am new to image processing so i am really confused regarding the coordinate system with images. I have a sample image and i am trying to rotate it 45 clockwise. My <strong>transformation</strong> matrix is <code>T = [ [cos45 sin45] [-sin45 cos45] ]</code></p>
  
  <p>Here is the code:</p>
  
  <pre><code>import numpy as np
  from matplotlib import pyplot as plt
  from skimage import io
  
  image = io.imread('sample_image')
  img_transformed = np.zeros((image.shape), dtype=np.uint8)
  
  trans_matrix = np.array([[np.cos(45), np.sin(45)], [-np.sin(45), np.cos(45)]])
  
  for i, row in enumerate(image):
      for j,col in enumerate(row):
          pixel_data = image[i,j] #get the value of pixel at corresponding location
          input_coord = np.array([i, j]) #this will be my [x,y] matrix
          result = trans_matrix @ input_coord 
          i_out, j_out = result #store the resulting coordinate location
  
          #make sure the the i and j values remain within the index range
          if (0 &lt; int(i_out) &lt; image.shape[0]) and (0 &lt; int(j_out) &lt; image.shape[1]):
              img_transformed[int(i_out)][int(j_out)] = pixel_data
  
  plt.imshow(img_transformed, cmap='gray')
  </code></pre>
  
  <p>The image comes out distorted and doesn't seems right. I know that in pixel coordinate, the origin is at the top left corner (row, column). is the rotation happening with respect to origin from the top left corner? is there a way to shift origin to center or any other given point?</p>
  
  <p>Thank you all!</p>