Hello,
I encounter some issues when importing FITS files from Fijifilm camera (X-H2) via Indigo A1 or AIN imager in SIRIL : the images are bottom up flipped and not debayered correctly (remain B&W). I noticed the FITS images headers created by the indigo software are not correctly tagged : BAYERPAT= ‘GRBG’ and the xtrans matrix is 6x6. But it doesn’t explain the bottom-up problem. If I import and regular RAF Fuji raw file I have no issue.
I wrote (thaks to chatGPT…) an astropy/numpy script that corrects the orientation and also corrects the BAYERPAT keyword for SIRIL. I join it.
I also had to filp upside down the xtrans matrix to have a correctly oriented.
Here is the script:
#!/usr/bin/env python3
import os
import shutil
import numpy as np
from astropy.io import fits
Value to assign to the BAYERPAT keyword
new_bayerpat = ‘RBGBRGGGRGGBGGBGGRBRGRBGGGBGGRGGRGGB’
Directory to save the processed files
siril_dir = ‘siril’
Ensure the ‘siril’ directory exists
if not os.path.exists(siril_dir):
os.makedirs(siril_dir)
Function to process FITS files
def process_fits_files():
# List all files in the current directory
for filename in os.listdir(‘.’):
# Check if the file has a .fits extension and avoid hidden macOS files starting with ‘.’
if filename.endswith(‘.fits’) and not filename.startswith('.’):
print(f"Processing file: {filename}")
try:
# Open the FITS file in read-only mode first to avoid potential issues
with fits.open(filename) as hdul:
# Check if the primary HDU exists and contains valid data
if len(hdul) > 0 and hdul[0].data is not None:
# Read the image data and make sure it is properly flipped
data = hdul[0].data
flipped_data = np.flipud(data) # Apply vertical flip
# Modify the BAYERPAT keyword
hdul[0].header['BAYERPAT'] = new_bayerpat
# Create a new FITS file with flipped data and updated header
new_filename = filename.replace('.fits', '_flipped_xtrans_corrected.fits')
new_filepath = os.path.join(siril_dir, new_filename)
# Now save the file in the 'siril' directory
hdu = fits.PrimaryHDU(data=flipped_data, header=hdul[0].header)
hdu.writeto(new_filepath, overwrite=True)
print(f"Saved flipped file as: {new_filepath}")
else:
print(f"No valid data found in {filename}")
except Exception as e:
print(f"Error processing {filename}: {e}")