Skip to content

Commit d53cbde

Browse files
Fix imports and white norm size
1 parent 5bf8fb6 commit d53cbde

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/labthings_picamera2/thing.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from typing import Annotated, Any, Iterator, Literal, Mapping, Optional, Self
2525
from contextlib import contextmanager
2626
import piexif
27-
from scipy.ndimage import zoom
27+
from scipy.ndimage import zoom, convolve
2828
from scipy.interpolate import interp1d
2929
from PIL import Image
3030
from threading import RLock
@@ -134,6 +134,7 @@ class ImageProcessingInputs(BaseModel):
134134
@dataclass
135135
class ImageProcessingCache:
136136
white_norm: np.ndarray
137+
white_norm_bl: np.ndarray
137138
gamma: interp1d
138139
ccm: np.ndarray
139140

@@ -681,10 +682,17 @@ def generate_image_processing_cache(
681682
white_norm = zoom(p.white_norm_lores, zoom_factors, order=1)[
682683
: (p.raw_size[1]//2), : (p.raw_size[0]//2), :
683684
]
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+
]
684691
ccm = np.array(p.colour_correction_matrix).reshape((3,3))
685692
gamma = interp1d(p.gamma[:, 0] / 255, p.gamma[:, 1] / 255)
686693
return ImageProcessingCache(
687694
white_norm=white_norm,
695+
white_norm_bl=white_norm_bl,
688696
ccm = ccm,
689697
gamma = gamma,
690698
)
@@ -729,9 +737,10 @@ def process_raw_array(
729737
packed = buffer.reshape((-1, raw.stride))
730738
if bilinear_demosaic:
731739
rgb = demosaicing_bilinear(raw_to_8bit_bayer(packed, raw.size))
740+
normed = rgb / p.white_norm_bl
732741
else:
733742
rgb = rggb2rgb(raw2rggb(packed, raw.size))
734-
normed = rgb / p.white_norm
743+
normed = rgb / p.white_norm
735744
corrected = np.dot(
736745
p.ccm, normed.reshape((-1, 3)).T
737746
).T.reshape(normed.shape)

0 commit comments

Comments
 (0)