Flipped and badly debayered FITS files from Fuji X-H2 camera and Indigo A1 or AIN software

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}")

Execute the function

Hello.

RAW files are read by the LibRaw library. It does not depend on Siril. I see that this camera is relatively recent, and this may explain why it is not read correctly.

I had an answer from the developer of Indigo suite :

I did some experiments and it looks like Siril does not observe the ROWORDER keyword. and it assumes the images are always bottom-up. And we produce TOP-DOWN images and indicate this in the HEADER

Maybe SIRIL could think about taking in consideration the ROWORDER key-word ? As the flipped issue do not append in Pinxinsight ?

Also even if the camera brand and model are indicated in the FITS header SIRIL does not seem to take it in consideration.

fits_fuji_bayerpat.py.zip (1.1 KB)

that’s a funny thing to say because ROWORDER was created by the Siril team.

So that’s not RAW images if they are FITS, and if the acquisition software is not able to give the correct BAYERPAT, it’s not really our problem.

Yes Siril displays images bottom-up, like the FITS convention: Siril - FAQ . When plate solving the result image in the usual processing workflow, if it’s flipped it will be put back in the correct orientation.

1 Like

Thanks ! I give your answer to the developpers of Indigo.