我想在 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 顯示它?還假設您平均兩個綠色值?任何幫助表示贊賞。
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?
uj5u.com熱心網友回復:
The answer was to use OpenCV to debayer the image and then normalise the data.
import cv2
debayered_image = cv2.cvtColor(imagedata, cv2.COLOR_BayerBG2BGR)
normalised_image = cv2.normalize(debayered_image, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
imgplot = plt.imshow(normalised_image)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/442587.html
標籤:python matplotlib image-processing astropy fits
上一篇:區分具有相似顏色的附加物件
下一篇:將兩個影像標簽組合成一個標簽
