davemlz / eemont

A python package that extends Google Earth Engine.
https://eemont.readthedocs.io/
MIT License
417 stars 69 forks source link

Image histogram matching #35

Closed aazuspan closed 3 years ago

aazuspan commented 3 years ago

Building off of what was discussed in #32, this would be an ee.Image method for histogram matching adapted from this implementation by Noel Gorelick.

The user would specify the target image and two lists of matching bands for the source and target images. The output would be an image with the source bands histogram-matched to the target bands (and maybe a new property saying the image ID it was matched to.)

# Source image
l7 = ee.Image("LANDSAT/LE07/C01/T1_SR/LE07_044029_20140105")
# Target image
l8 = ee.Image("LANDSAT/LC08/C02/T1_L2/LC08_044029_20140113")

# R, G, B bands of source image
l7_bands = ["B3", "B2", "B1"]
# Corresponding bands of target image
l8_bands = ["B4", "B3", "B2"]

# Match the source image's histogram to the target image's histogram.
l7_matched  = l7.matchHistogram(target=l8, sourceBands=l7_bands, targetBands=l8_bands)

It should be possible to implement this for ee.ImageCollection, too, by matching each image in the collection to the target image and returning the collection, but I'm not sure how useful that would be. What do you think, @davemlz?

Feel free to assign me :)

EDIT: Actually, how about using a dictionary of bands instead of two lists? No chance of mismatched band numbers, less chance for mixing up bands, and the lists will be combined into a dictionary anyways to map over. Just a thought!

# Source image
l7 = ee.Image("LANDSAT/LE07/C01/T1_SR/LE07_044029_20140105")
# Target image
l8 = ee.Image("LANDSAT/LC08/C02/T1_L2/LC08_044029_20140113")

# R, G, B bands of source image (keys) and corresponding bands of the target image (values)
bands = {
  "B3": "B4", 
  "B2": "B3", 
  "B1": "B2"
}

# Match the source image's histogram to the target image's histogram.
l7_matched  = l7.matchHistogram(target=l8, bands=bands)
davemlz commented 3 years ago

Hey, @aazuspan!

I really like this, go for it! :rocket:

I think the ee.ImageCollection method would be really difficult to implement since for each image in the collection we would have to check the closest valid image in the other collection. For now, let's do it just for ee.Image objects :)

And regarding the use of a dictionary instead of two lists, I like it!

I'll assign you this now :)

If you need anything, just let me know!

Cheers!

aazuspan commented 3 years ago

Sounds like a good plan! I'll submit this in the same PR as #32.