×

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

Bi-monthly release with minor bug fixes and improvements

Need simple python script to display INDI captured FITS files

  • Posts: 41
  • Thank you received: 3
I am having trouble displaying RGB FITS files that were captured by my Nikon, using INDI from the Python cli.
Sample code that I have found out on the interwebs don't work very well with 'real' RGB FITS files.

Opening the file and reading the header yields:
Filename: ./M_57_Light_001.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU      52   (6016, 4016, 3)   uint8

The first problem that I hacked my way through was the need to 'reshape' the image data after opening it.
image_data = fits.getdata(image_file)
image_data = image_data.reshape(image_data.shape[2],image_data.shape[1],image_data.shape[0])

After reshaping the data, calling
plt.imshow(image_data,origin='lower')
plt.show()
yields a black rectangle.

(when using any image processing program, stars can be seen in the original image, even without stretching, so the image does have visible data)

Does anyone have an actual, simple example of displaying a DSLR-captured , RGB image in FITS format that was written by INDI?

Thanks in advance!
Dan
1 month 1 week ago #99753

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

  • Posts: 261
  • Thank you received: 66
Something like this should work. DSLRs are normally in JPEG mode by default with INDI, which is why you are dealing with FITS RGB data. If you switch your camera to RAW mode, this becomes a little more complex with having to debayer and scale the data.
import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
 
 
hdulist = fits.open(image_file)
 
image_data = hdulist[0].data
 
# FITS RGB data needs to be reshaped
image_data = np.swapaxes(image_data, 0, 2)
image_data = np.swapaxes(image_data, 0, 1)
 
# image data is now RGB
 
plt.imshow(image_data)
plt.show()
The following user(s) said Thank You: R Dan Nafe
1 month 1 week ago #99757

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

  • Posts: 261
  • Thank you received: 66
1 month 1 week ago #99759

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

  • Posts: 41
  • Thank you received: 3
Thanks, Aaron, this worked perfectly.
The call to np.swapaxes (twice!) was the thing that was needed.
Last edit: 1 month 1 week ago by R Dan Nafe.
1 month 1 week ago #99791

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

  • Posts: 261
  • Thank you received: 66
It is not very obvious, but FITS stores RGB image data with the matrix axes as "color, height, width" where most programs expect "height, width, color". FITS effectively stores 3 monochrome images for R, G, and B (on the first axis). In the scientific world, it was probably more interesting to view each channel separately than as a combined image.

Numpy has some very nice methods for altering matrices.
The following user(s) said Thank You: R Dan Nafe
1 month 1 week ago #99792

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

Time to create page: 0.507 seconds