如何将3个高范围JPEG2000图像合并为一个RGB图像? [英] How to combine 3 high range JPEG2000 images into single RGB one?

查看:123
本文介绍了如何将3个高范围JPEG2000图像合并为一个RGB图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码下载Sentinel-2图像

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')

然后我在磁盘上得到了3张灰度的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.

我想要这样的东西:

或预览

我的版本是

(对不起)

UDPATE

我发现图像可能是12位的.当我尝试12岁时,我发现曝光过度.因此,从实验上我发现最好的质量是14位.

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

尽管即使使用14位,我也有很小的过度曝光区域.这是巴哈马:

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

推荐答案

我今天调查了这个问题,我认为您的问题是部门划分.就像kazemakase所说,明智的做法是将255乘以最大值,把didiv乘以最大值,但是矩阵很大(因为太大而无法处理). 我用了这个:

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)

您也使用了错误的乐队(我想,但我不确定!).红色应该是波段5,蓝色应该是波段1或2.请参见 https://en.wikipedia. org/wiki/Sentinel-2#Instruments 以获得更多详细信息.

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.

不幸的是,频段1和5的数据远小于频段3.因此,我用cv2调整了大小(PIL在大小和全部方面都遇到了麻烦).因此,这产生了相当少的计算错误,并且新图片看起来并不好看.

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.

这篇关于如何将3个高范围JPEG2000图像合并为一个RGB图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆