from macslib import * from numpy import * from numpy.linalg import inv from math import * # PUT YOUR IMAGE NAME IN THE QUOTES! img = loadImage('cat.jpg') numRows = len(img) numCols = len(img[0]) enableModify = True enableTranslate = True # IMAGE MODIFICATION if enableModify: img[5][5] = 0 # MATRIX TRANSFORMS if enableTranslate: # This is the transform matrix. You can edit this! transform = array([ [1, 0, 0], [0, 1, 0], [0, 0, 1]]) # These will center the transform center = [numCols/2, numRows/2] centerCoordsMatrix = array([ [1, 0, -center[0]], [0, 1, -center[1]], [0, 0, 1 ]]) antiCenterCoordsMatrix = array([ [1, 0, center[0]], [0, 1, center[1]], [0, 0, 1 ]]) transform = antiCenterCoordsMatrix.dot(transform).dot(centerCoordsMatrix) srcImg = img img = zeros((numRows,numCols)) # We are going to solve the problem backwards, so we invert the transform (like how - undoes +) invertedTransform = inv(transform) for row in range(numRows): for col in range(numCols): # A (x,y) pixel in the new image: pixel = array([[col],[row],[1]]) # Find the source pixel using matrix (dot) multiplication: srcPixel = invertedTransform.dot(pixel) srcCol,srcRow = int(srcPixel[0][0]),int(srcPixel[1][0]) # If the source pixel is within the image, copy it to the final image: if srcRow>=0 and srcRow=0 and srcCol