1

I am exporting image assets to my google drive as GeoTiffs. Each asset was originally created by clipping an image to a feature and then reprojected to a slightly coarser resolution. Therefore when using the inspector in code editor, pixels not fully covered by the polygon have a weighted value shown in brackets after the absolute pixel value.

I am aware reductions like reduceRegions uses these weightings (unless you specify an unweighted() reduction). But I was wondering if there is a way to use the weightings when exporting an image asset to drive?

Ideally, for this analysis, if the absolute value of a pixel in code editor is 1000 and the pixel weighting shows as 50%, then the value exported to the GeoTIFF in my drive would be 500, whereas currently it seems to remain 1000.

Hopefully the description is clear enough, but say if you need a code example.

1
  • If you could provide a code sample with some with clipping and reprojecting it would be helpful.
    – JonasV
    Commented Aug 20, 2020 at 7:50

1 Answer 1

1

The “weightings” are known as the image's mask.

if the absolute value of a pixel in code editor is 1000 and the pixel weighting shows as 50%, then the value exported to the GeoTIFF in my drive would be 500, whereas currently it seems to remain 1000.

You can modify the pixel values in this way by exporting image.multiply(image.mask()).

You might also want to try combining this with unmask and updateMask to convert to an image whose mask is always 1 (100%); this image will display within Earth Engine more like what you're wanting to export, but it won't modify anything but the mask.

Demo script:

// resample() ensures that the edges of this image will be partially masked by
// interpolation between masked and unmasked pixels, so it demonstrates the
// effects of what we're going to do to it.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_001004_20140524').resample();

// Convert the image to fully unmasked:
var unmasked = image
    // Convert fully masked pixels (only) to zero.
    .unmask(0, false)
    // Convert partially-masked pixels (only) to fully masked pixels with the same value.
    .updateMask(1);

// Multiply the unmasked image by the mask; this gives the same effect
// as mosaicing or visualizing the original masked image on top of
// a zero/black image.
var multiplied = unmasked.multiply(image.mask());

Map.setCenter(-21.85161, 78.02296, 16);
Map.addLayer(image, {}, "Original");
Map.addLayer(unmasked, {}, "Unmasked");
Map.addLayer(multiplied, {}, "Multiplied");
Map.addLayer(image.multiply(image.mask()), {}, "Multiplied w/o unmasking", false);

https://code.earthengine.google.com/287cbf2109e1b8e2ed06a9d5aa1cbb54

4
  • Very useful, thanks Kevin. Just what I wanted to hear. I realise I had missed out investigating masks properly and had been relying on updateMask, selfMask and unmask. I will try this in my workflow and get back to you if any issues applying it.
    – AndyArnell
    Commented Aug 20, 2020 at 18:55
  • @AndyArnell I highly recommend playing around with extremely zoomed in images (as my demo script does) to understand what masking is doing. Also, masks are essentially the same thing as "alpha channels" in regular image processing.
    – Kevin Reid
    Commented Aug 20, 2020 at 20:12
  • Just adding that I managed to use this approach successfully, and to say thanks again @KevinReid!
    – AndyArnell
    Commented Aug 27, 2020 at 9:54
  • @AndyArnell Glad to hear it! If you're satisfied, please accept my answer by clicking the checkmark on the left side. This marks the question as not in need of further answering (and, when there are multiple answers, highlights the one you accepted).
    – Kevin Reid
    Commented Aug 27, 2020 at 13:49

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.