wildtreetech / sentinel2-bot

🛰📷🌏 Tweeting pictures taken by the Sentinel 2 satellite.
https://twitter.com/sentinel2bot
MIT License
36 stars 11 forks source link

Adaptive brightness adjustment #15

Closed betatim closed 7 years ago

betatim commented 7 years ago

https://twitter.com/Sentinel2Bot/status/786480930508705792

Some images are very very dark. One way of improving on that is to use some kind of adaptive adjusting of colours/brightness.

betatim commented 7 years ago

A start on using adaptive histogram equalisation and skimage instead of imagemagick.

def load(directory):
     r = io.imread(directory+"/B04.jp2")
     g = io.imread(directory+"/B03.jp2")
     b = io.imread(directory+"/B02.jp2")
     return (r,g,b)

def smaller(r,g,b):
     r2 = transform.resize(r, (4000, 4000))
     g2 = transform.resize(g, (4000, 4000))
     b2 = transform.resize(b, (4000, 4000))
     return (r2,g2,b2)

def process(r,g,b):
     rgb = np.dstack((r,g,b))
     rgb_ = exposure.equalize_adapthist(rgb, clip_limit=0.03)
     return transform.resize(rgb_, (500,500))

rc, gc, bc = load("/tmp/tiles-china/")
rc2,gc2,bc2 = smaller(rc,gc,bc)
rgb_c = process(rc2, gc2, bc2)

dropping down to 4000x4000 before doing equalize_adapthist doesn't seem to do much to the quality of the result but dramatically speeds up processing and reduces memory. For the bot you'd probably want to choose something a bit bigger and resize the final image to ~1000x1000 as we do currently.

Compare these new images:

screen shot 2016-10-14 at 10 35 04

to these old ones: <img width="50%" src="https://pbs.twimg.com/media/Cus3cBkVUAAxsg_.jpg"/ >

betatim commented 7 years ago

Get the input tiles:

# snow
wget http://sentinel-s2-l1c.s3.amazonaws.com/tiles/45/T/YN/2015/11/28/0/B0{2,3,4}.jp2
# sand
wget http://sentinel-s2-l1c.s3.amazonaws.com/tiles/32/R/KQ/2015/7/4/0/B0{2,3,4}.jp2
betatim commented 7 years ago

Since merging #18 the colours seem much better and brightness is also Ok in most images.