How can I replace masked pixels with another image?

I have two sets of images: Image_A and Image_B, each has 10 bands.

I want to change the masked pixels in Image_A by the corresponding (same band, line, and column) values from Image_B.

Image_A_Update = Image_A.updateMask(Image_A.unmask(Image_B))

If Image_B also has a mask for some pixels, the output would be the mask for those pixels.

1 Answer 1

var Image_A_Update = Image_B.blend(Image_A);

This will be unmasked wherever at least one of the images is unmasked, using pixels from Image_A if available and pixels from Image_B otherwise.

(This is the same operation as ImageCollection.mosaic(), just applied to two images instead of an entire collection.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.