×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Saved fits not debayred

  • Posts: 59
  • Thank you received: 19
Hello

if I take an image with setting: Controls, Format, RGB 24 and open it with gimp 2.10,
dialog: Load Fits File: Image Composing NAXIS=3, NAXIS3=2,...,4 I see an RGB image.

If I switch to: Controls, Format 16 bit, I see with INDI fits viewer an RGB image and if
I save it (as FITS, no other choice), I see the RGGB pattern and in gimp it is of type
greyscale and the RGGB pattern is clearly visible.

What are the steps to convert an 16 bit RGGB image to, eg. 16 bit TIFF, or any other
format?

Kind regards, wildi

camera: ASI294MC
indi_asi_ccd driver settings: Controls, Format Raw 16 bit
kstars settings: auto debayer: true, 3d cube: true
Ubuntu: DISTRIB_RELEASE=19.04, DISTRIB_CODENAME=disco
INDIlib repo: ppa.launchpad.net/mutlaqja/ppa/ubuntu disco InRelease
4 years 6 months ago #43741

Please Log in or Create an account to join the conversation.

You need a software (like PixInsight) to perform the debayering.
The following user(s) said Thank You: Markus Wildi
4 years 6 months ago #43753

Please Log in or Create an account to join the conversation.

  • Posts: 59
  • Thank you received: 19
Hello

Jasem, thanks for your hint.

To keep things simple, I wrote a minimal example Python script, which performs the conversion from RGGB data, stored in a FITS File, to an RGB numpy array which is stored as a 16 bit PNG file.
The RGB array comes in two variants, interpolated and non-interpolated. For the latter case I adapted code from Osmo Systems' picamraw.

Provide a FITS file in the directory where this script is executed and rename it to 4sec.fits.

bye, wildi

#!/usr/bin/env python3                                                                                                                                                                                         
 
'''                                                                                                                                                                                                            
  Fetch RGGB data from FITS file, convert it to an RGB numpy                                                                                                                                                   
  array, with and without interpolation, and store it as                                                                                                                                                       
  uint16 PNG. This code serves as an example.                                                                                                                                                                  
 
  Variant "no interpolation" based on Osmo Systems' picamraw.                                                                                                                                                  
 
  Requires Python >= 3.5                                                                                                                                                                                       
 
  Markus Wildi, 2019                                                                                                                                                                                           
 
'''                                                                                                                                                                                                            
 
import cv2                                                                                                                                                                                                     
from astropy.io import fits                                                                                                                                                                                    
 
import numpy as np                                                                                                                                                                                             
from enum import Enum                                                                                                                                                                                          
 
# source: adapted from Osmo Systems' picamraw (https://github.com/osmosystems/picamraw).                                                                                                                       
 
class BayerOrder(Enum):                                                                                                                                                                                        
    ''' There are four supported arrangements of the R, G, G, and B pixels:                                                                                                                                    
        RGGB:                                                                                                                                                                                                  
              RG                                                                                                                                                                                               
              GB                                                                                                                                                                                               
        GBRG:                                                                                                                                                                                                  
              GB                                                                                                                                                                                               
              RG                                                                                                                                                                                               
        BGGR:                                                                                                                                                                                                  
              BG                                                                                                                                                                                               
              GR                                                                                                                                                                                               
        GRBG:                                                                                                                                                                                                  
              GR                                                                                                                                                                                               
              BG                                                                                                                                                                                               
    '''                                                                                                                                                                                                        
 
    RGGB = 'RGGB'                                                                                                                                                                                              
    GBRG = 'GBRG'                                                                                                                                                                                              
    BGGR = 'BGGR'                                                                                                                                                                                              
    GRBG = 'GRBG'                                                                                                                                                                                              
 
R_CHANNEL_INDEX, G_CHANNEL_INDEX, B_CHANNEL_INDEX = [0, 1, 2]                                                                                                                                                  
 
BAYER_ORDER_TO_RGB_CHANNEL_COORDINATES = {                                                                                                                                                                     
    # (ry, rx), (gy, gx), (Gy, Gx), (by, bx)                                                                                                                                                                   
    BayerOrder.RGGB: ((0, 0), (1, 0), (0, 1), (1, 1)),                                                                                                                                                         
    BayerOrder.GBRG: ((1, 0), (0, 0), (1, 1), (0, 1)),                                                                                                                                                         
    BayerOrder.BGGR: ((1, 1), (0, 1), (1, 0), (0, 0)),                                                                                                                                                         
    BayerOrder.GRBG: ((0, 1), (1, 1), (0, 0), (1, 0)),                                                                                                                                                         
}                                                                                                                                                                                                              
 
def _guard_attribute_is_a_multiple_of(attribute_name, attribute_value, multiple):                                                                                                                              
    if not attribute_value % multiple == 0:                                                                                                                                                                    
        raise ValueError(                                                                                                                                                                                      
            'Incoming data is the wrong shape: {attribute_name} ({attribute_value}) is not a multiple of {multiple}'                                                                                           
            .format(**locals())                                                                                                                                                                                
        )                                                                                                                                                                                                      
 
 
bggr = fits.getdata('4sec.fits')                                                                                                                                                                               
#                                                                                                                                                                                                              
# variant without interpolation                                                                                                                                                                                
#                                                                                                                                                                                                              
_guard_attribute_is_a_multiple_of('width', bggr.shape[0], 2)                                                                                                                                                   
_guard_attribute_is_a_multiple_of('height', bggr.shape[1], 2)                                                                                                                                                  
 
rgb_no_int = np.zeros((int(bggr.shape[0]/2), int(bggr.shape[1]/2), 3))                                                                                                                                         
 
((ry, rx), (gy, gx), (Gy, Gx), (by, bx)) = BAYER_ORDER_TO_RGB_CHANNEL_COORDINATES[BayerOrder.RGGB]                                                                                                             
 
rgb_no_int[:, :, R_CHANNEL_INDEX] = bggr[ry::2, rx::2]                                                                                                                                                         
rgb_no_int[:, :, G_CHANNEL_INDEX] = (bggr[gy::2, gx::2] + bggr[Gy::2, Gx::2])/2.                                                                                                                               
rgb_no_int[:, :, B_CHANNEL_INDEX] = bggr[by::2, bx::2]                                                                                                                                                         
cv2.imwrite( '4sec_no_int.png', rgb_no_int.astype(np.uint16))                                                                                                                                                  
#                                                                                                                                                                                                              
# variant with interpolation                                                                                                                                                                                   
#                                                                                                                                                                                                              
rgb = cv2.cvtColor(bggr, cv2.COLOR_BAYER_BG2RGB)                                                                                                                                                               
 
cv2.imwrite('4sec_int.png', rgb)    
The following user(s) said Thank You: Jasem Mutlaq, Teseo
4 years 6 months ago #43851

Please Log in or Create an account to join the conversation.

thanks, that would be quite useful to many out there. KStars debayer the image for viewing purposes only since it does not modify the image itself.
4 years 6 months ago #43855

Please Log in or Create an account to join the conversation.

  • Posts: 14
  • Thank you received: 0
Thanks! I was looking for something like that...
3 years 7 months ago #59323

Please Log in or Create an account to join the conversation.

Time to create page: 0.377 seconds