【发布时间】:2018-03-20 02:35:36
【问题描述】:
我正在尝试从'.fits' 文件打开全彩图像。但是,将其与相应的'.gif' 图像进行比较时,其颜色和大小似乎存在错误。
如何查看正确尺寸的真彩色图像?
例如,可以选择'.fits' 文件和对应的'.gif' 文件located at the top of this webpage。下面是我的示例代码,它使用了APLPY 模块。
def from_fits_to_image(color_scheme, rloc, rname='synop_Ml_0.2104', rext='.fits', cmap=None):
"""
color_scheme : 'rgb', 'grayscale', or 'false color'; color scheme of image to be shown
rloc : type <str>; location of file to be read
rname : type <str>; name of file to be read
rext : type <str>; extension of file to be read
cmap : None or type <str>; colormap
"""
rpath = rloc + rname + rext
if color_scheme == 'rgb':
pic = aplpy.FITSFigure(rpath)
# pic.show_rgb(alt_filename) # what filename is supposed to go here?
else:
pic = aplpy.FITSFigure(rpath)
if color_scheme == 'grayscale':
pic.show_grayscale()
elif color_scheme == 'false color':
if cmap is None:
pic.show_colorscale()
else:
pic.show_colorscale(cmap=cmap)
# plt.savefig(...)
plt.show()
只要提供正确的rloc(下载的'.fits'文件的位置)和color_scheme,上面的代码就会运行。
调用下面的函数将显示正确尺寸的空白图。为了使它不为空,我必须提供另一个现有的文件名,但我不清楚它到底应该是什么。
from_fits_to_image(color_scheme='rgb', rloc=rloc)
下面的每个函数调用都显示了一个已调整为小图的图。虽然color_scheme='grayscale' 似乎可以正确着色绘图,但其他方法不能正确着色图像。
from_fits_to_image('grayscale', rloc=rloc)
from_fits_to_image('false color', rloc=rloc)
from_fits_to_image('false color', rloc=rloc, cmap='plasma')
为了比较,下面是'.gif' 图像。理想情况下,输出将与下图完全相同。
编辑:
我尝试使用astropy、PIL 和pyfits 均未成功。任何帮助将不胜感激。
编辑 2:
以下是使用来自astropy.io 的fits 的结果。
from astropy.io import fits
def reada(rloc, rname='synop_Ml_0.1998', rext='.fits'):
""" """
rpath = rloc + rname + rext
# hdu_list = fits.open(rpath)
# hdu_list.info()
pic = fits.getdata(rpath)
plt.imshow(pic)
plt.show()
reada(rloc=rloc)
我玩过vmin 和vmax kwargs,但没有成功。此外,使用pyfits 打开文件会导致以下错误,即使使用pyfits.open(rpath, uint=True, do_not_scale_image_data=True):
TypeError: Image data can not convert to float
【问题讨论】:
-
gif图片是怎么产生的?你确定这不是假彩色图像?对于真彩色 rgb 图像,您通常需要组合通过红/绿/蓝滤镜拍摄的三张图像,但您提供的 fit 文件中只有一张图像。
-
我不确定这些图像是如何产生的,尽管 gif 图像乍一看似乎是正确的,因为该图像描绘了太阳在太阳自转过程中的表面。我将阅读该网站以获取更多信息。至于组合三个图像过滤器,PIL 和 APLPY 有提取 RGB 过滤数据的方法。我是否错误地假设不能通过对图片进行三次(或一次有效)采样来生成 3 个 RGB 过滤数据数组?如果没有,是否可以从 fit 图像重新创建 gif 图像?
-
我不确定是否可以从单个阵列生成 3 个 rgb 图像。也许在太阳天体物理学中有一些技巧可以做到这一点,但制作 rgb 图像背后的整个想法是使用三张图像,每张图像中都携带着独立的信息,所以我对此表示怀疑。
-
现在我看,我认为你的gif图像确实是一个假彩色的。等一下,我会起草一个答案。
标签: python python-3.x python-imaging-library fits aplpy