Skip to content

This program converts .fits file to .jpg. Fits to jpeg.

Notifications You must be signed in to change notification settings

psds075/fitstoimg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Fits To Image in Python

  • This program converts .fits file to .jpg file. (Or you can convert fits file to png or bmp in little modification)

Installation

  • Command git clone https://github.com/psds075/fitstoimg.git.
  • Make new folder 'data' and 'image' in current directory, and copy .fits files to data folder. (mkdir data, mkdir image)
  • Command python fitstoimg.py.
  • In linux environment, you should revise directory character '\' -> '/'.
  • It is tested on Windows 10, Linux Ubuntu 16.04.
$ git clone https://github.com/psds075/fitstoimg.git
$ mkdir data
$ mkdir image
$ python3 fitstoimg.py

Code (fitstoimg.py)

import os
import numpy as np
from PIL import Image
from astropy.io import fits
import img_scale

dir_path = os.getcwd()
for filename in os.listdir(dir_path+"\\data"):
    if filename.endswith(".fits"):
        image_data = fits.getdata("data\\"+filename)
        if len(image_data.shape) == 2:
            sum_image = image_data
        else:
            sum_image = image_data[0] - image_data[0]
            for single_image_data in image_data:
                sum_image += single_image_data  

        sum_image = img_scale.sqrt(sum_image, scale_min=0, scale_max=np.amax(image_data))
        sum_image = sum_image * 200
        im = Image.fromarray(sum_image)
        if im.mode != 'RGB':
            im = im.convert('RGB')
    
        im.save(dir_path+"\\image\\"+filename+".jpg")
        im.close()

Contact

About

This program converts .fits file to .jpg. Fits to jpeg.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages