如何使用 python 显示 16 位彩色 FITS 图像
我想在 python 中显示 FITS 图像。我使用 astropy(FITS 加载程序)、matplotlib 和灰度图像完成所有这些工作。然而,我有 16 位颜色的图像,带有 RGGB 拜耳矩阵,但我不知道如何将其显示为 RGB 彩色图像。
这适用于灰度图像:
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
m42 = fits.open('FITS Data/frame-u-006073-4-0063.fits')
imagedata = m42[0].data
plt.imshow(imagedata, cmap='gray')
plt.colorbar()
但是我有第二个图像,每像素 16 位,我不知道如何将这些位映射到 r、g、b 值并在 matplotlib 中显示它们。
例如(第一个像素是 3148):
pixel = imagedata[0][0]
r = (pixel & 0b1111000000000000) >> 12
g = (pixel & 0b0000111100000000) >> 8
g = int((g + ((pixel & 0b0000000011110000) >> 4)) / 2)
b = pixel & 0b0000000000001111
分别为红色、绿色和蓝色给出 0、8 和 12。如何将整个数组imagedata
映射到RGB并让matplotlib显示它?还假设您对两个绿色值进行平均?任何帮助表示赞赏。
更新:我是否误解了带有拜耳矩阵的 16 位图像的格式?每像素完整 16 位是 R、G、G 还是 B?在什么情况下我需要先对图像进行去马赛克/去拜耳处理?
I want to display a FITS image in python. I have all this working using astropy (the FITS loader) and matplotlib and a greyscale image. However I have images that are 16 bit colour with a Bayer matrix of RGGB and I don't know how to display this as an RGB colour image.
This works for a greyscale image:
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
m42 = fits.open('FITS Data/frame-u-006073-4-0063.fits')
imagedata = m42[0].data
plt.imshow(imagedata, cmap='gray')
plt.colorbar()
However I have a second image that is 16 bits per pixel and I don't know how to map the bits to r, g, b values and display them in matplotlib.
For example (first pixel is 3148):
pixel = imagedata[0][0]
r = (pixel & 0b1111000000000000) >> 12
g = (pixel & 0b0000111100000000) >> 8
g = int((g + ((pixel & 0b0000000011110000) >> 4)) / 2)
b = pixel & 0b0000000000001111
Gives 0, 8, and 12 for red, green, and blue respectively. How do I map the entire array imagedata
to RGB and get matplotlib to display it? Also assuming you average the two green values? Any help appreciated.
Update: Have I misunderstood the format of a 16 bit image with a Bayer matrix? Are the full 16 bits per pixel either R, G, G, or B? In which case do I need to look at demosaicing / debayering the image first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是使用 OpenCV 对图像进行去拜耳处理,然后对数据进行标准化。
The answer was to use OpenCV to debayer the image and then normalise the data.