if you want to undo drawImage changes, you must save canvas data before doing drawImage like:
tmp = canvas.getContext("2d").getImageData(0, 0, with, height);
//do changes here
canvas.getContext("2d").putImageData(tmp , 0, 0);
//here changes will be lost
this is unswer to the title, question content was not clear for me