I am trying to convert a raw cr2 image into .fits using imageio and PIL. But, I am unable to convert the image into .fits format
I am currently converting .cr2 into jpg as I am unable to convert .cr2 into .fits. (if possible = best). After conversion into jpg, I am opening the file and splitting the r,g,b into 3 different arrays and pass each array to a separate .fits file but, whenever I try to pass the entire data of r,g,b combined to array it never works.
import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
from PIL import Image
im = imageio.imread('E:\FYP\cr.cr2', format="RAW-FI")
imageio.imwrite(r'E:\FYP\1.jpg', im)
image = Image.open(r'E:\FYP\1.jpg')
xsize, ysize = image.size
print("Image size: {} x {}".format(xsize, ysize))
plt.imshow(image)
r, g, b = image.split()
r_data = np.array(r.getdata()) # data is now an array of length ysize*xsize
g_data = np.array(g.getdata())
b_data = np.array(b.getdata())
print(r_data.shape)
r_data = r_data.reshape(ysize, xsize)
g_data = g_data.reshape(ysize, xsize)
b_data = b_data.reshape(ysize, xsize)
red = fits.PrimaryHDU(data=r_data)
red.header['LATOBS'] = "32:11:56" # add spurious header info
red.header['LONGOBS'] = "110:56"
red.writeto(r'E:\FYP\red.fits')
It gives me single-colored .fits image while i want is an image with all R,G,B colors as .fits image.