Skip to content

Commit

Permalink
rename api
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYer22 committed Jan 6, 2022
1 parent 5ee685e commit 3fbfee2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
# process_raw: A python package to process raw and dng file
# `process_raw`: A python package to process raw and dng file

## Feature
- [x] Reading dng file
- [x] Saving dng file
- [x] Demosaicing
- [x] Demosaicing with pow (for raw image > 8bit)
## Features
- [x] Reading `.dng` file to `np.array`
- [x] Saving raw image as `.dng` file
- [x] Demosaicing (by rawpy)
- [x] Demosaicing with [gamma correction](https://en.wikipedia.org/wiki/Gamma_correction) (for raw image > 8bit)

## Usage
**Install**
```bash
# Install
pip install process_raw
```
**Python example:**
```Python
import cv2
from process_raw import DngFile

# Download raw.dng for test:
# wget https://github.com/yl-data/yl-data.github.io/raw/master/2201.process_raw/raw-12bit-GBRG.dng
dng_path = "./raw-12bit-GBRG.dng"

# Run example
python3 -m process_raw.process_raw
dng = DngFile.read(dng_path)
rgb1 = dng.postprocess() # demosaicing by rawpy
cv2.imwrite("rgb1.jpg", rgb1[:, :, ::-1])
rgb2 = dng.demosaicing(poww=0.3) # demosaicing with gamma correction
cv2.imwrite("rgb2.jpg", rgb2[:, :, ::-1])
DngFile.save(dng_path + "-save.dng", dng.raw, bit=dng.bit, pattern=dng.pattern)
```

**Run demo:**
```bash
python -m process_raw.process_raw
```
For document, please see example code of `DngFileformat.test()` at [`process_raw/process_raw.py`](process_raw/process_raw.py#L154)
For document, please see example code of `DngFile.test()` at [`process_raw/process_raw.py`](process_raw/process_raw.py#L154)

## Credits
Source referenced from:
- [PiDNG](https://github.com/schoolpost/PiDNG): for save dng file
- [rawpy](https://github.com/letmaik/rawpy): for read dng file
- [rawpy](https://github.com/letmaik/rawpy): for read `.dng` file
- [PiDNG](https://github.com/schoolpost/PiDNG): for save raw as `.dng` file
- [colour_demosaicing](https://github.com/colour-science/colour-demosaicing): Provide demosaicing algorithms
2 changes: 1 addition & 1 deletion process_raw/__info__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
__description__ = "process_raw"
__license__ = "MIT"
__author__ = "DIYer22"
Expand Down
21 changes: 12 additions & 9 deletions process_raw/process_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def test(raw=None):
boxx.g()


class DngFileformat:
class DngFile:
@staticmethod
def save_dng(dng_path, raw, bit=12, pattern="GBRG", compress=False, Orientation=1):
def save(dng_path, raw, bit=12, pattern="GBRG", compress=False, Orientation=1):
try:
from pidng.core import RAW2DNG, DNGTags, Tag
except ModuleNotFoundError as e:
Expand Down Expand Up @@ -122,7 +122,7 @@ def save_dng(dng_path, raw, bit=12, pattern="GBRG", compress=False, Orientation=
# compress = True lossless for bayer, 29MB => 19 MB

@staticmethod
def read_dng(dng_path):
def read(dng_path):
import rawpy

class RawPy_(rawpy.RawPy):
Expand Down Expand Up @@ -161,25 +161,28 @@ def test():
print(cmd)
assert not os.system(cmd)

dng = DngFileformat.read_dng(dngp)
dng = DngFile.read(dngp)
raw = dng.raw

with boxx.timeit("dng.postprocess(demosaicing by rawpy)"):
rgb1 = dng.postprocess()
with boxx.timeit("dng.demosaicing with poww"):
with boxx.timeit("dng.demosaicing with gamma correction"):
rgb2 = dng.demosaicing(poww=0.3)
boxx.tree(dict(raw=raw, rgb1=rgb1, rgb2=rgb2))

DngFileformat.save_dng(
dngp + "-save.dng", raw, bit=dng.bit, pattern=dng.pattern
)
DngFile.save(dngp + "-save.dng", raw, bit=dng.bit, pattern=dng.pattern)
boxx.g()
return raw

read_dng = read
save_dng = save


DngFileformat = DngFile

if __name__ == "__main__":
from boxx import *

raw = DngFileformat.test()
raw = DngFile.test()
print("--------RawToRgbUint8.test--------")
RawToRgbUint8.test(raw)

0 comments on commit 3fbfee2

Please sign in to comment.