|
1 | 1 | # 趣味のPython学習 Project 02-12 |
2 | 2 | # Python RAW 2 TIFF CONVERTER |
3 | | -# ばーじょん 0.1.1 |
| 3 | +# ばーじょん 0.1.2 |
4 | 4 |
|
5 | | -ver = "0.1.1" |
| 5 | +ver = "0.1.2" |
6 | 6 |
|
7 | 7 | # NEED THIS ! get 'pillow' with pip command ! |
8 | 8 | from PIL import Image |
|
34 | 34 |
|
35 | 35 | raw = RPY.imread(fnm) |
36 | 36 |
|
| 37 | + tif = raw.postprocess(demosaic_algorithm=RPY.DemosaicAlgorithm.LINEAR,output_bps=16) |
| 38 | + |
37 | 39 | width = raw.sizes.width |
38 | 40 | height = raw.sizes.height |
39 | 41 | clr = raw.color_desc |
|
44 | 46 | print("PATTERN:",clr) |
45 | 47 | print(pat) |
46 | 48 |
|
47 | | - tif = raw.postprocess(demosaic_algorithm=RPY.DemosaicAlgorithm.LINEAR,output_bps=16) |
48 | | - rgb = raw.postprocess(demosaic_algorithm=RPY.DemosaicAlgorithm.LINEAR,four_color_rgb=True,output_color=RPY.ColorSpace.raw,output_bps=16) |
49 | | - |
50 | 49 | print("*** READ OK ***") |
51 | 50 |
|
52 | 51 | except LibRawIOError: |
|
63 | 62 |
|
64 | 63 | if type(pat) != numpy.ndarray : continue |
65 | 64 |
|
66 | | - fno = fnm + ".reb.png" |
| 65 | + rgb = raw.postprocess(half_size=True,four_color_rgb=True,output_color=RPY.ColorSpace.raw,output_bps=16) |
| 66 | + |
| 67 | + fno = fnm + ".rb.png" |
67 | 68 | print(f"*** SAVE : {fno} ( 16bit bayer pattern ) ***") |
68 | 69 |
|
69 | 70 | img_cv = Image.new('I;16',(width,height)) |
70 | 71 |
|
71 | 72 | for y in range(height) : |
72 | 73 | for x in range(width) : |
73 | 74 |
|
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 |
| 75 | + if x%2 == 0 and y%2 == 0 : c = 0 |
| 76 | + if x%2 == 1 and y%2 == 0 : c = 1 |
| 77 | + if x%2 == 0 and y%2 == 1 : c = 3 |
| 78 | + if x%2 == 1 and y%2 == 1 : c = 2 |
79 | 79 |
|
80 | | - img_cv.putpixel((x,y),int(rgb[y][x][c])) |
| 80 | + img_cv.putpixel((x,y),int(rgb[y//2][x//2][c])) |
81 | 81 |
|
82 | 82 | img_cv.save(fno) |
83 | 83 |
|
|
0 commit comments