Skip to content

Commit ea7a7a3

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

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/labthings_picamera2/thing.py

Lines changed: 12 additions & 2 deletions
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,11 +682,19 @@ 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,
697+
white_norm=white_norm,
689698
gamma = gamma,
690699
)
691700

@@ -729,9 +738,10 @@ def process_raw_array(
729738
packed = buffer.reshape((-1, raw.stride))
730739
if bilinear_demosaic:
731740
rgb = demosaicing_bilinear(raw_to_8bit_bayer(packed, raw.size))
741+
normed = rgb / p.white_norm_bl
732742
else:
733743
rgb = rggb2rgb(raw2rggb(packed, raw.size))
734-
normed = rgb / p.white_norm
744+
normed = rgb / p.white_norm
735745
corrected = np.dot(
736746
p.ccm, normed.reshape((-1, 3)).T
737747
).T.reshape(normed.shape)

0 commit comments

Comments
 (0)