gpt4 book ai didi

python - 使用 make_lupton_rgb 获取深色图像

转载 作者:行者123 更新时间:2023-12-04 10:13:47 27 4
gpt4 key购买 nike

在这种情况下,我正在使用 astropy 可视化来制作 M66 的彩色图像。
在做任何事情之前,我了解到我必须使用 转换我的 RGB .fts 数组。 numpy.float_()

forCasting = np.float_()

### READING
b = fits.open("data/"+"M66-Blue.fts")[0].data
r = fits.open("data/"+"M66-Red.fts")[0].data
g = fits.open("data/"+"M66-Green.fts")[0].data

### CASTING
r = np.array(r,forCasting)
g = np.array(g,forCasting)
b = np.array(b,forCasting)

这样我就可以继续我的拉伸(stretch)运动:
stretch = SqrtStretch() + ZScaleInterval()

r = stretch(b)
g = stretch(r)
b = stretch(g)

plt.imshow(r, origin='lower')
plt.show()
plt.imshow(g, origin='lower')
plt.show()
plt.imshow(b, origin='lower')
plt.show()

那我就用方法 make_lupton_rgb 来自 astropy.visualizaion 如下,但我有一个 超暗图像我无法区分任何东西。有人知道为什么我在这里有一个黑暗的最终图像吗?你有什么建议吗?
### SAVING
# rgb_default = make_lupton_rgb(r, g, b, minimum=1000, stretch=900, Q=100, filename="provafinale.png")
rgb_default = make_lupton_rgb(r, g, b, filename="provafinale.png")
plt.imshow(rgb_default, origin='lower')
plt.show()

谢谢!

最佳答案

看来您必须设置 stretchQ make_lupton_rgb 的参数.
默认值为 stretch=5Q=8 ,这给出了黑暗的结果。

我没有使用 astropy 的经验或与天文学。
我只是玩了参数,并使用 stretch=1 获得了明亮的图像和 Q=0 .

rgb_default = make_lupton_rgb(r, g, b, minimum=0, stretch=1, Q=0, filename="provafinale.png")

我试过计算 minimumstretch使用 np.percentile , 用于线性拉伸(stretch)输出。

我使用 m8_050507_9i9m 测试了代码图片来自 index_fits .

这是我用于测试的代码:
import numpy as np
from astropy.io import fits
from astropy.visualization import SqrtStretch
from astropy.visualization import ZScaleInterval
from astropy.visualization import make_lupton_rgb
from matplotlib import pyplot as plt

forCasting = np.float_()

### READING
# http://www.mistisoftware.com/astronomy/index_fits.htm
r = fits.open("m8_050507_9i9m_R.FIT")[0].data
g = fits.open("m8_050507_9i9m_G.FIT")[0].data
b = fits.open("m8_050507_9i9m_B.FIT")[0].data

# Crop the top and the right margin (contains black pixels)
r = r[:, :-200]
g = g[:, :-200]
b = b[:, :-200]

### CASTING
r = np.array(r,forCasting)
g = np.array(g,forCasting)
b = np.array(b,forCasting)

stretch = SqrtStretch() + ZScaleInterval()

r = stretch(b)
g = stretch(r)
b = stretch(g)

plt.imshow(r, origin='lower')
plt.imshow(g, origin='lower')
plt.imshow(b, origin='lower')

### SAVING
# https://docs.astropy.org/en/stable/api/astropy.visualization.make_lupton_rgb.html
# astropy.visualization.make_lupton_rgb(image_r, image_g, image_b, minimum=0, stretch=5, Q=8, fil/ename=None)[source]
# Return a Red/Green/Blue color image from up to 3 images using an asinh stretch.
# The input images can be int or float, and in any range or bit-depth.

lo_val, up_val = np.percentile(np.hstack((r.flatten(), g.flatten(), b.flatten())), (0.5, 99.5)) # Get the value of lower and upper 0.5% of all pixels

stretch_val = up_val - lo_val

rgb_default = make_lupton_rgb(r, g, b, minimum=lo_val, stretch=stretch_val, Q=0, filename="provafinale.png")

# Cut the top rows - contains black pixels
rgb_default = rgb_default[100:, :, :]

plt.imshow(rgb_default, origin='lower')
plt.show()

结果:
enter image description here

关于python - 使用 make_lupton_rgb 获取深色图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61179993/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com