MatLab code: im2patch (convert image to patches) and patch2im (convert pathes to image)