Using homogeneous coordinates to rotate an image
Rather than looping over all x and y values you could put them into a vector, that should speed things up considerably.

y=repmat(1:cols,rows,1)
x=repmat((1:rows)',cols,1)

M=[x(:) y(:) ones(rows*cols,1)];


Now you just need to multiply M or M' with T or T' and you have subsitituted that part of the code.