Skip to content

Commit d5957e2

Browse files
authored
bugfix radiance correction for mnlocs (#39)
* experimental support for high dynamic radiance maps * comment fixes * rm Manifolds deps, should not be there * bugfix radiace correction mnlocs
1 parent 3104bc2 commit d5957e2

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

src/services/RadianceCorrection.jl

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,17 @@ normalized_image = CameraModels.recoverRadianceWeighted_RGB(imgs, est_lΔT, [gr,
137137
See also: `randomPixels`, `normalizeRadianceMap`, `recoverRadianceWeighted_RGB`, `_pixvalWindow`
138138
"""
139139
function solveDetectorResponse(
140-
Z::AbstractVector,
141-
logΔTs::AbstractVector;
140+
Z_logΔTs::AbstractVector{<:Tuple{<:AbstractVector, <:AbstractVector}};
142141
n::Int = 2^8, # common for 3*8 bit RGB;
143142
window::AbstractVector{<:Real} = _pixvalWindow.(0:(n-1)),
144143
λ::Real = 200.0,
145144
diff_kernel::AbstractVector{<:Real} = SA[1, -2, 1],
146145
)
146+
mnimgs = (s->length(first(s))).(Z_logΔTs)
147+
mnlocs = (s->length(first(s)[1])).(Z_logΔTs)
148+
147149
# System size
148-
nimgs = length(Z)
149-
nlocs = length(Z[1])
150+
nlocs = +(mnlocs...)
150151

151152
# Prepare a linear system.
152153
# The total number of equations (neqs), which includes:
@@ -155,30 +156,41 @@ function solveDetectorResponse(
155156
# - n equations from smoothness regularization
156157
# A is size (neqs, Zmax-Zmin+pixel_locations)
157158
# A = [A1 A2; A3 0], where
158-
# A{1,2} is has rows that each contain two column entries such that, gcurve[zij] = logExposure_ij + logΔt_j
159-
# - a1: the weight at column z (observed pixel value) and next available column
160-
# - a2: the negative weight at column n+i (corresponding to list_i of pixel locations)
161-
# A2 is also off-diagonal
159+
# A{1,2} is has rows that each contain two column entries such that, w*gcurve[zij] - w*logE_ij = w*logΔt_j
160+
# - a1: the weight at column z (observed pixel value)
161+
# - a2: the negative weight at column n+i (corresponding to log exposure of observed pixel location i)
162+
# A2 has striped around the it's diagonal
162163
# A3 is the weighted regularization as off diagnonal entries for smoothness of gcurve, and
163164
# b has length (neqs) = [weighted logΔTs; zeros(n)]
164-
# x = [gcurve; = A * b
165-
# logExposure]
165+
# Ax = b => A * [gcurve; = [weighted logΔTs;
166+
# logExposure] zeros(n)]
166167
#
167-
neqs = nlocs*nimgs + 1 + n
168+
neqs = sum(mnlocs.*mnimgs) + 1 + n
168169
A = zeros(neqs,n+nlocs)
169170
b = zeros(neqs)
170171

171172
# Fill in the equations from pixel value observations in A and b,
172-
# Note the number of equations is nlocs*nimgs, where each pixel value observation contributes one equation.
173+
# Note the number of equations is sum(mnlocs.*mnimgs), where each pixel value observation contributes one equation.
173174
k = 1;
174-
for i in 1:nlocs, j in 1:nimgs
175-
# A1 columns correspond to gcurve possible pixel z values,
176-
# A2 columns correspond to logExposure of observed pixels from list of locations i
177-
pixz1 = Z[j][i] + 1
178-
a_12 = view(A, k, SA[pixz1, n+i])
179-
a_12 .= window[pixz1] .* SA[1, -1]
180-
b[k] = window[pixz1] * logΔTs[j]
181-
k += 1
175+
offset = 0
176+
for m in 1:length(Z_logΔTs)
177+
Z = Z_logΔTs[m][1]
178+
logΔTs = Z_logΔTs[m][2]
179+
# i is the pixel location index, j is the image index, zij is the observed pixel value at location i in image j
180+
locsperimg = length(Z[1])
181+
for i in 1:locsperimg
182+
for j in 1:length(Z)
183+
# A1 columns correspond to gcurve possible pixel z values,
184+
# A2 columns correspond to logExposure of observed pixels from list of locations i
185+
pixz1 = Z[j][i] + 1
186+
miloc = offset+n+i
187+
a_12 = view(A, k, [pixz1, miloc])
188+
a_12 .= window[pixz1] .* SA[1, -1]
189+
b[k] = window[pixz1] * logΔTs[j]
190+
k += 1
191+
end
192+
end
193+
offset += locsperimg
182194
end
183195

184196
# Add the equation to fix the curve by setting its middle value to 0
@@ -204,6 +216,14 @@ function solveDetectorResponse(
204216
return gcurve, logExposure
205217
end
206218

219+
function solveDetectorResponse(
220+
Z::AbstractVector,
221+
logΔTs::AbstractVector;
222+
kw...
223+
)
224+
solveDetectorResponse([(Z, logΔTs);]; kw...)
225+
end
226+
207227

208228
function normalizeRadianceMap(
209229
rm,
@@ -218,9 +238,9 @@ end
218238

219239

220240
function recoverRadianceWeighted(
221-
imgs,
222-
logΔts,
223-
gcurve;
241+
imgs::AbstractVector{<:AbstractMatrix},
242+
logΔts::AbstractVector{<:Real},
243+
gcurve::AbstractVector{<:Real};
224244
window::AbstractVector{<:Real} = _pixvalWindow.(0:(2^8 - 1)),
225245
normalize_percentile::Real = 0.02, # set <= 0 to disable
226246
)
@@ -249,9 +269,9 @@ end
249269

250270

251271
function recoverRadianceWeighted_RGB(
252-
imgs,
253-
logΔts,
254-
gcurve_rgb;
272+
imgs::AbstractVector{<:AbstractMatrix{<:RGB{N0f8}}},
273+
logΔts::AbstractVector{<:Real},
274+
gcurve_rgb::AbstractVector{<:AbstractVector{<:Real}};
255275
window::AbstractVector{<:Real} = _pixvalWindow.(0:(2^8 - 1)),
256276
normalize_percentile::Real = 0.02, # set <= 0 to disable
257277
)

0 commit comments

Comments
 (0)