Transform-invariant Image Decomposition with Similarity Templates