code for texture synthesis