The solution I could think of is using a mask to remember the pixel you want to keep, then you first update all the pixels to get a new image I', then merge the original image I by
I_out = I * mask + I'