How to combine 3 high range JPEG2000 images into single RGB one?

安稳与你 提交于 2019-12-24 11:15:19

问题


I am downloading Sentinel-2 images with the following code

import boto3

s3 = boto3.resource('s3', region_name='us-east-2')
bucket = s3.Bucket('sentinel-s2-l1c')
path = 'tiles/36/R/UU/2017/5/14/0/'

object = bucket.Object(path + 'B02.jp2')
object.download_file('B02.jp2')
object = bucket.Object(path + 'B03.jp2')
object.download_file('B03.jp2')
object = bucket.Object(path + 'B04.jp2')
object.download_file('B04.jp2')

and I get 3 grayscale JP2 images on disk.

Then I am trying to mix color layers with the following code

import matplotlib.image as mpimg
import numpy as np
from PIL import Image

Image.MAX_IMAGE_PIXELS = 1000000000

print('Reading B04.jp2...')
img_red = mpimg.imread('B04.jp2')

print('Reading B03.jp2...')
img_green = mpimg.imread('B03.jp2')

print('Reading B02.jp2...')
img_blue = mpimg.imread('B02.jp2')

img = np.dstack((img_red, img_green, img_blue))

img = np.divide(img, 256)
img = img.astype(np.uint8)

mpimg.imsave('MIX.jpeg', img, format='jpg')

Result looks very poor, very dimmed and nearly black and white.

I would like something like this:

or like preview

while my version is

(sorry)

UDPATE

I found that images probably 12-bit. When I tried 12, I saw overexposure. So experimentally I found the best quelity is for 14 bitness.

UDPATE 2

Although even with 14 bits I have small areas of overexposure. Here are Bahamas:


回答1:


I looked into this problem today and I think you problem is the division. Like kazemakase said it is wise to multiply by 255 and divice by the max value but the matrix is very big (as in too big to handle). I used this:

max_pixel_value = rgb_image.max()
rgb_image = np.multiply(rgb_image, 255.0)
rgb_image = np.divide(rgb_image, max_pixel_value)
rgb_image = rgb_image.astype(np.uint8)

Also you used the wrong bands (I think, but I am not sure!). Red should be band 5 and blue 1 or 2. See https://en.wikipedia.org/wiki/Sentinel-2#Instruments for more details.

Unfortunately the data of band 1 and 5 is much smaller then of band 3. Therefore I resized it with cv2 (PIL had trouble with the size and all). So this made quite the few calculation errors and the new picture does not look much better.



来源:https://stackoverflow.com/questions/44157201/how-to-combine-3-high-range-jpeg2000-images-into-single-rgb-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!