Pixel casting works as well as the write image function. This code is rather amazing.