如何记录拉伸 FITS 图像并更改其对比度?

How do you log stretch a FITS image and change its contrast?

我正在尝试将 astropy 2.0.11 与 python 2.7.15 结合使用,通过对其应用对数拉伸并更改对比度来编辑适合的图像,但我无法确定出来了。

我一直在尝试按照 astropy 网站上的教程打开和操作 fits 文件,但我想知道这些教程是否只适用于最新版本的 astropy 和 python 3 ?

对我的代码组织感到抱歉。这是原型代码,我只是想测试一些东西并让它工作。

import time
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import astropy.visualization
from astropy.io import fits
from astropy.utils.data import download_file
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)
from astropy.utils.data import get_pkg_data_filename


def main():

    #My own fits file
    #fitsImage = get_pkg_data_filename("C:\20180807T000456.fits")

    fitsImage = download_file('http://data.astropy.org/tutorials/FITS-images/HorseHead.fits', cache=True )

    hdu_list = fits.open(fitsImage)
    hdu_list.info()

    #norm = ImageNormalize(stretch=LogStretch())

    image_data = fits.getdata(fitsImage)
    print(type(image_data))
    print(image_data.shape)


    hdu_list.close()

    plt.figure()
    plt.imshow(image_data, cmap='gray', norm=LogNorm())
    plt.colorbar()

    # I chose the tick marks based on the histogram above
    cbar = plt.colorbar(ticks=[5.e3,1.e4,2.e4])
    cbar.ax.set_yticklabels(['5,000','10,000','20,000'])

    time.sleep(10)

我也无法使用 plt.imshow()

显示图像

任何见解都会有所帮助

你太接近了!我 运行 你的代码在 Python 2.7 中,你需要做的就是添加

plt.show()

time.sleep(10) 之前(你有什么理由包括这个?)然后你得到

此外,我认为您不需要包含 colorbaryticklabelsplt.imshow 会自动添加具有对数范数比例的颜色栏(我在我评论该部分时得到图像)。