Skip to content

Commit b481436

Browse files
authored
Add files via upload
1 parent 630daa2 commit b481436

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

raw2tiff.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# 趣味のPython学習 Project 02-12
22
# Python RAW 2 TIFF CONVERTER
3-
# ばーじょん 0.1.2
3+
# ばーじょん 0.1.3
44

5-
ver = "0.1.2"
5+
ver = "0.1.3"
66

77
# NEED THIS ! get 'pillow' with pip command !
88
from PIL import Image
@@ -15,6 +15,7 @@
1515

1616
# NEED THIS ! get 'rawpy' with pip command !
1717
import rawpy as RPY
18+
from rawpy import LibRawFileUnsupportedError
1819
from rawpy import LibRawIOError
1920

2021
#
@@ -32,12 +33,15 @@
3233

3334
try :
3435

35-
raw = RPY.imread(fnm)
36+
# CHECK EXIST
37+
f = open(fnm,'rb')
38+
f.close()
3639

37-
tif = raw.postprocess(demosaic_algorithm=RPY.DemosaicAlgorithm.LINEAR,output_bps=16)
40+
raw = RPY.imread(fnm)
3841

3942
width = raw.sizes.width
4043
height = raw.sizes.height
44+
4145
clr = raw.color_desc
4246
pat = raw.raw_pattern
4347

@@ -48,35 +52,45 @@
4852

4953
print("*** READ OK ***")
5054

51-
except LibRawIOError:
55+
except FileNotFoundError:
5256
print(f"{fnm} : not found !")
5357

54-
except AssertionError:
58+
except LibRawIOError:
59+
print(f"{fnm} : decode error !")
60+
61+
except LibRawFileUnsupportedError:
5562
print(f"{fnm} : type error !")
5663

5764
else :
5865

5966
fno = fnm + ".tif"
6067
print(f"*** SAVE : {fno} ( 48bit color ) ***")
61-
imageio.imsave(fno,tif)
6268

63-
if type(pat) != numpy.ndarray : continue
69+
tif = raw.postprocess(demosaic_algorithm=RPY.DemosaicAlgorithm.LINEAR,output_bps=16)
70+
imageio.imsave(fno,tif)
6471

65-
rgb = raw.postprocess(half_size=True,four_color_rgb=True,output_color=RPY.ColorSpace.raw,output_bps=16)
72+
ptn = True
73+
if type(pat) != numpy.ndarray :
74+
ptn = False
6675

6776
fno = fnm + ".rb.png"
6877
print(f"*** SAVE : {fno} ( 16bit bayer pattern ) ***")
6978

79+
80+
rgb = raw.postprocess(half_size=True,four_color_rgb=True,output_color=RPY.ColorSpace.raw,output_bps=16)
7081
img_cv = Image.new('I;16',(width,height))
7182

7283
for y in range(height) :
7384
for x in range(width) :
7485

86+
# RGGB CONVERT
7587
if x%2 == 0 and y%2 == 0 : c = 0
7688
if x%2 == 1 and y%2 == 0 : c = 1
7789
if x%2 == 0 and y%2 == 1 : c = 3
7890
if x%2 == 1 and y%2 == 1 : c = 2
7991

92+
if ptn == False and c == 3 : c = 1
93+
8094
img_cv.putpixel((x,y),int(rgb[y//2][x//2][c]))
8195

8296
img_cv.save(fno)

0 commit comments

Comments
 (0)