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

问题描述 投票:1回答:1

我正在尝试使用带有python 2.7.15的astropy 2.0.11来编辑拟合图像,通过对其应用日志拉伸并改变对比度,我无法弄明白。

我一直在尝试按照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()显示图像

任何见解都会有所帮助

python python-2.7 astropy fits
1个回答
2
投票

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

plt.show()

time.sleep(10)之前(任何理由你包括这个?)你得到enter image description here

此外,我认为你不需要包括colorbaryticklabelsplt.imshow会自动添加带有lognorm标度的颜色条(当我得到图像时,我评论了该部分)。

© www.soinside.com 2019 - 2024. All rights reserved.