|
24 | 24 | from typing import Annotated, Any, Iterator, Literal, Mapping, Optional, Self |
25 | 25 | from contextlib import contextmanager |
26 | 26 | import piexif |
27 | | -from scipy.ndimage import zoom |
| 27 | +from scipy.ndimage import zoom, convolve |
28 | 28 | from scipy.interpolate import interp1d |
29 | 29 | from PIL import Image |
30 | 30 | from threading import RLock |
@@ -134,6 +134,7 @@ class ImageProcessingInputs(BaseModel): |
134 | 134 | @dataclass |
135 | 135 | class ImageProcessingCache: |
136 | 136 | white_norm: np.ndarray |
| 137 | + white_norm_bl: np.ndarray |
137 | 138 | gamma: interp1d |
138 | 139 | ccm: np.ndarray |
139 | 140 |
|
@@ -681,10 +682,17 @@ def generate_image_processing_cache( |
681 | 682 | white_norm = zoom(p.white_norm_lores, zoom_factors, order=1)[ |
682 | 683 | : (p.raw_size[1]//2), : (p.raw_size[0]//2), : |
683 | 684 | ] |
| 685 | + zoom_factors_bl = [ |
| 686 | + i / n for i, n in zip(p.raw_size[::-1], p.white_norm_lores.shape[:2]) |
| 687 | + ] + [1] |
| 688 | + white_norm_bl = zoom(p.white_norm_lores, zoom_factors_bl, order=1)[ |
| 689 | + : (p.raw_size[1]), : (p.raw_size[0]), : |
| 690 | + ] |
684 | 691 | ccm = np.array(p.colour_correction_matrix).reshape((3,3)) |
685 | 692 | gamma = interp1d(p.gamma[:, 0] / 255, p.gamma[:, 1] / 255) |
686 | 693 | return ImageProcessingCache( |
687 | 694 | white_norm=white_norm, |
| 695 | + white_norm_bl=white_norm_bl, |
688 | 696 | ccm = ccm, |
689 | 697 | gamma = gamma, |
690 | 698 | ) |
@@ -729,9 +737,10 @@ def process_raw_array( |
729 | 737 | packed = buffer.reshape((-1, raw.stride)) |
730 | 738 | if bilinear_demosaic: |
731 | 739 | rgb = demosaicing_bilinear(raw_to_8bit_bayer(packed, raw.size)) |
| 740 | + normed = rgb / p.white_norm_bl |
732 | 741 | else: |
733 | 742 | rgb = rggb2rgb(raw2rggb(packed, raw.size)) |
734 | | - normed = rgb / p.white_norm |
| 743 | + normed = rgb / p.white_norm |
735 | 744 | corrected = np.dot( |
736 | 745 | p.ccm, normed.reshape((-1, 3)).T |
737 | 746 | ).T.reshape(normed.shape) |
|
0 commit comments