How to reslice polydata insert into imagedata?

Looking at this code might help: