Skip to content

Commit be44de8

Browse files
davidplowmannaushir
authored andcommitted
utils: raspberrypi: ctt: Fix NaNs in lens shading tables
The problem occurs when the calculation could lead to a final row (or column) of grid squares with no pixels in them (and hence, NaNs). One specific case is a Pi 5 with an image width (or height) of 1364, so that's 682 Bayer quads. To give 32 grid squares it was calculating 22 quads per cell. However, 31 * 22 = 682 leaving nothing in the final column. The fix is to do a rounding-down division by the number of cells minus one, rather than a rounding-up division by the number of cells. This turns the corner case from one where the final row/column has no pixels to one where we don't quite cover the full image, which is how we have to handle these cases. Signed-off-by: David Plowman <[email protected]>
1 parent 2993e79 commit be44de8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

utils/raspberrypi/ctt/ctt_alsc.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0)
127127
channels = [Img.channels[i] for i in Img.order]
128128
"""
129129
calculate size of single rectangle.
130-
-(-(w-1)//32) is a ceiling division. w-1 is to deal robustly with the case
131-
where w is a multiple of 32.
130+
The divisions here must ensure the final row/column of cells has a non-zero number of
131+
pixels.
132132
"""
133133
w, h = Img.w/2, Img.h/2
134-
dx, dy = int(-(-(w-1)//grid_w)), int(-(-(h-1)//grid_h))
134+
dx, dy = (w - 1) // (grid_w - 1), (h - 1) // (grid_h - 1)
135+
135136
"""
136137
average the green channels into one
137138
"""

0 commit comments

Comments
 (0)