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

时间:2019-02-14 21:52:25

标签: python python-2.7 astropy fits

我正在尝试将astropy 2.0.11与python 2.7.15配合使用,以对其进行对数拉伸并更改对比度来编辑合适的图像,但我一直无法弄清楚。

我一直试图按照astropy网站上的教程来打开和操作拟合文件,但是我想知道这些教程是否仅适用于最新版本的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()

显示图片

任何见解都会有所帮助

1 个答案:

答案 0 :(得分:2)

您是如此亲密!我在Python 2.7中运行了您的代码,您所需要做的就是添加

plt.show()

time.sleep(10)之前(您是否包括此内容?),您会得到enter image description here

此外,我认为您不需要包括colorbaryticklabelsplt.imshow会自动将色标添加为lognorm比例(我在获得图片)。