Skip to content

Commit

Permalink
Merge pull request #3 from eaydin/fix-3
Browse files Browse the repository at this point in the history
New Major Version
  • Loading branch information
eaydin authored May 21, 2017
2 parents 725455c + ae4dbbb commit d4e46a5
Show file tree
Hide file tree
Showing 6 changed files with 10,795 additions and 293 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pyc
.ppm
.ipynb
.cr2
.ppm
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 - M. Emre AYDIN

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 0 additions & 27 deletions README.markdown

This file was deleted.

89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
cr2fits
=======

cr2fits.py version **2.1.0**
https://github.com/eaydin/cr2fits

A script to convert RAW images (Canon, Nikon etc.) to FITS images. It extracts only one color channel of the RAW image, and writes the necessary EXIF information to the FITS header.

# Dependencies

- Python 2.7 or Python >= 3.2
- PyFITS or astropy: Older versions cr2fits (1.0.3 and earlier) depended on PyFITS. From 2.0.0 and on it added support for astropy. It uses astropy.io.fits which is basically the same as PyFITS for now. Favors PyFITS over astropy if you have both, since it is faster to load.
- dcraw: Try getting the latest version of this. Usually the ones in repositories is not the latest so it's possible that it'll convert your RAW images differently, corrupted. Get the latest version here : http://www.cybercom.net/~dcoffin/dcraw/ Also the one distributed with this package should work.

# Compiling dcraw:

Either use `gcc -o dcraw -O4 dcraw.c -lm -ljasper -ljpeg -llcms2` or `gcc -o dcraw -O4 dcraw.c -lm -DNODEPS` to compile it.
You can then copy `dcraw` to your path (ex. `/usr/local/bin`). In order to copy to your path, you'll probably need root privileges.

# Usage

`cr2fits.py <cr2-filename> <color-index>`

- cr2-filename: This will obviously be the name of the file to convert.
- color-index: Can take one of four values, either 0, 1, 2, 3 which represent Red, Green, Blue and Unscaled Raw respectively.

If you want to use it as a module:

```
from cr2fits import cr2fits
# Assuming there's a test.cr2 in the current directory
# And we want the Blue Channel
a = cr2fits("test.cr2", 2)
# Read into the raw image
a.read_cr2()
# Now you have a.pbm_bytes which is the output of dcraw
# Get the EXIF data
a.read_exit()
# Now you have values such as a.shutter, a.date, a.iso ...
# Convert dcraw output to Numpy Array using netpbm
im_ppm = a.read_pbm(a.pbm_bytes)
# Since we want only one channel (ex. Blue) use get_color
im_blue = a.get_color(im_ppm, a.colorInput)
# Create FITS file from Blue Image and EXIF data
fits_image = a.create_fits(im_blue)
# If you want to write output, _generate_destination gets filename
dest = a._generate_destination(a.filename, a.colorInput)
# Write FITS file to generated destination (or elsewhere)
a.write_fits(fits_image, dest)
```

Also, the method convert does all this for you.

```
from cr2fits import cr2fits
a = cr2fits("test.cr2", 2)
a.convert()
```

# Output

The script will output the FITS file, added the color channel to the name of the output.

# Change log

## 2.1.0
- Added support for unscaled raw output.
- Fixed output name detection fails with dot's (.) in the name.
- Detects if output filename exists and gives alternative name

## 2.0.0
- Added support for astropy
- Added support for usage as a module
- Use Numpy slicing instead of looping
- Direct dcraw output to BytesIO object, avoiding the I/O for the unused PPM file
- Updated license

# todo
- Add support for configparser
- Add support for 3D FITS files: an idea from the fork by [@mireianievas](https://github.com/mireianievas)
- Add support for multiple file inputs
Loading

0 comments on commit d4e46a5

Please sign in to comment.