Skip to content

Commit 972a658

Browse files
authored
Add files via upload
1 parent 640c1ef commit 972a658

5 files changed

Lines changed: 93 additions & 1 deletion

File tree

png08debayer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ def debayer3x3RGGB(img,x,y) :
140140

141141
print("*** DONE ***")
142142

143+
#END OF FILE
143144

png08rebayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ def rebayer3x3RGGBrev(img,x,y) :
181181

182182
print("*** DONE ***")
183183

184-
# EBD OF FILE
184+
#END OF FILE

png16debayer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,5 @@ def change_val(st,val) :
376376
img_cv.save(fno)
377377

378378
print("DONE !")
379+
380+
#END OF FILE

png16tiff.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,6 @@ def bytes1(val) :
242242
cv2.imwrite(fno,img_cv)
243243

244244
print("DONE !")
245+
246+
#END OF FILE
247+

raw2tiff.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# 趣味のPython学習 Project 02-12
2+
# Python RAW 2 TIFF CONVERTER
3+
# ばーじょん 0.1.0
4+
5+
ver = "0.1.0"
6+
7+
8+
# NEED THIS ! get 'pillow' with pip command !
9+
from PIL import Image
10+
11+
# NEED THIS ! get 'numpy' with pip command !
12+
import numpy
13+
14+
# NEED THIS ! get 'imageio' with pip command !
15+
import imageio
16+
17+
# NEED THIS ! get 'rawpy' with pip command !
18+
import rawpy as RPY
19+
from rawpy import LibRawIOError
20+
21+
#
22+
# IMPORTANT !!!
23+
# rawpy needs LibRaw Libraly !
24+
# https://www.libraw.org/
25+
#
26+
27+
# MAIN
28+
29+
print(f"*** RAW FILE to TIFF CONVERTER VERSION {ver} ***")
30+
print("\nSELECT RAW FILE\n")
31+
32+
while len( fnm := input("file : ") ) > 0 :
33+
34+
try :
35+
36+
raw = RPY.imread(fnm)
37+
38+
width = raw.sizes.width
39+
height = raw.sizes.height
40+
clr = raw.color_desc
41+
pat = raw.raw_pattern
42+
43+
print(f"W : {width} H : {height}")
44+
45+
print("PATTERN:",clr)
46+
print(pat)
47+
48+
rgb = raw.postprocess(demosaic_algorithm=RPY.DemosaicAlgorithm.LINEAR,four_color_rgb=True,output_color=RPY.ColorSpace.raw,output_bps=16)
49+
50+
print("*** READ OK ***")
51+
52+
except LibRawIOError:
53+
print(f"{fnm} : not found !")
54+
55+
except AssertionError:
56+
print(f"{fnm} : type error !")
57+
58+
else :
59+
60+
fno = fnm + ".tif"
61+
print(f"*** SAVE : {fno} ( 48bit color ) ***")
62+
imageio.imsave(fno,rgb)
63+
64+
if type(pat) != numpy.ndarray : continue
65+
66+
fno = fnm + ".reb.png"
67+
print(f"*** SAVE : {fno} ( 16bit bayer pattern ) ***")
68+
69+
img_cv = Image.new('I;16',(width,height))
70+
71+
for y in range(height) :
72+
for x in range(width) :
73+
74+
if x%2 == 0 and y%2 == 0 : c = pat[0][0]
75+
if x%2 == 1 and y%2 == 0 : c = pat[0][1]
76+
if x%2 == 0 and y%2 == 1 : c = pat[1][0]
77+
if x%2 == 1 and y%2 == 1 : c = pat[1][1]
78+
if c == 3 : c = 1
79+
80+
img_cv.putpixel((x,y),int(rgb[y][x][c]))
81+
82+
img_cv.save(fno)
83+
84+
print("*** DONE ! ***")
85+
86+
# END OF FILE

0 commit comments

Comments
 (0)