Photo Consistency Check
Check if a 3D point is photo-consistent across multiple views.
In multi-view stereo (MVS), we reconstruct 3D points by finding locations that project to similar colors in all images. A point is photo-consistent if the variance of its projected colors is below a threshold:
σ2=N1∑i(ci−cˉ)2<τ2
where:
- ci is the color in view i
- cˉ is the mean color across views
- τ is the consistency threshold
Photo consistency is checked for each color channel independently. If any channel has high variance, the point is not consistent.
Example:
is_photo_consistent([(100, 100, 100), (102, 98, 101), (99, 101, 100)], 10)
True
- Checking photo consistency across 3 views:
- Red channel: [100, 102, 99] → mean=100.33, variance=1.56 < 100 ✓
- Green channel: [100, 98, 101] → mean=99.67, variance=1.56 < 100 ✓
- Blue channel: [100, 101, 100] → mean=100.33, variance=0.22 < 100 ✓ All channels have variance < 10² = 100, so point is consistent.
Constraints:
- colors: list of RGB tuples from different views
- threshold: maximum standard deviation for consistency
- Return True if all channels have variance < threshold²
A 3D point is photo-consistent if, when projected into several calibrated images, its observed colors are very similar across views, i.e., the per-channel color variance across views is below a given threshold. In this problem, you are given the colors of that point in multiple views and must decide, channel-wise, whether the variance is small enough.
1. Background Knowledge (Key Concepts)
-
Multi-view stereo (MVS): MVS uses multiple calibrated images of a scene to reconstruct dense 3D geometry. Given camera parameters and images, candidate 3D points are projected into each view, and their photometric consistency (color similarity) is used as a cue for whether the 3D point is likely to be real.
-
Photometric (photo) consistency: If a 3D point truly lies on a physical surface, then its projections in different views should have similar appearance (e.g., RGB values), up to lighting or noise. One common way to measure this is to compute the variance of the observed colors across views: low variance ⇒ similar colors ⇒ consistent; high variance ⇒ likely wrong 3D point (e.g., on background, occluded, or mismatched).
-
Channel-wise checking: Colors are usually represented as 3 channels (e.g., R, G, B). To be strict, the point must be consistent in each channel, so you compute variance independently for each channel and fail if any channel exceeds the threshold.
2. Algorithm / Approach Pattern
The generic pattern to solve this problem:
- For each color channel (R, G, B or similar):
- Collect the color values of that channel from all views.
- Compute the mean of these values.
- Compute the variance using the given formula.
- Compare the variance to the threshold squared, τ2.
- If all channels have variance < τ2, the point is photo-consistent; otherwise, it is not.
This is essentially a per-dimension variance test on a small 1D sample (the colors across views) for each channel.
3. Step-by-Step Strategy
Assume:
- You have N views.
- Colors are given as something like (R_i, G_i, B_i) for view i.
- Threshold is tau.
Steps:
- Separate channels
- Create three arrays:
- R = [R_1, R_2,..., R_N]
- G = [G_1, G_2,..., G_N]
- B = [B_1, B_2,..., B_N]
- Define a helper to compute variance (as in the formula):
- Mean: cˉ=N1∑i=1Nci
- Variance (using the provided definition with divisor N): σ2=N1∑i=1N(ci−cˉ)2
- Compute per-channel variance
- varR = variance(R)
- varG = variance(G)
- varB = variance(B)
- Compare with threshold
- Given tau, compute tau2 = tau * tau.
- Check:
- consistentR = (varR < tau2)
- consistentG = (varG < tau2)
- consistentB = (varB < tau2)
- Final decision
- Point is photo-consistent if: consistentR && consistentG && consistentB
- Otherwise, not consistent.
Example-style pseudocode
def is_photo_consistent(colors, tau):
# colors: list of (R, G, B) tuples across N views
N = len(colors)
# Split channels
R = [c for c in colors]
G = [c for c in colors]
B = [c for c in colors]
def variance(vals):
n = len(vals)
mean = sum(vals) / n
return sum((v - mean) ** 2 for v in vals) / n # matches given formula
tau2 = tau * tau
varR = variance(R)
varG = variance(G)
varB = variance(B)
return (varR < tau2) and (varG < tau2) and (varB < tau2)
4. Common Pitfalls
-
Using the wrong variance formula: The problem uses N1, not N−11. Make sure your implementation matches exactly.
-
Comparing to τ instead of τ2: The condition is σ2<τ2, so either:
-
compute variance and compare with tau * tau, or
-
compute standard deviation sqrt(variance) and compare with tau. The first is simpler and avoids a square root.
-
Integer division / overflow: If colors and sums are integers, convert to float before division to avoid truncation. In some languages, sum / N can be integer division if not careful.
-
Threshold logic: Ensure you implement “if any channel has high variance ⇒ inconsistent” as a logical OR of failures (equivalently, AND of successes for consistency).
5. Time & Space Complexity
Let:
-
N = number of views (number of color samples for the point)
-
C = number of channels (typically 3)
-
Time complexity:
-
Computing mean for each channel: O(N) per channel.
-
Computing variance for each channel: another O(N) per channel.
-
Total: O(C⋅N), which is O(N) for constant C (e.g., RGB).
-
Space complexity:
-
If you store channel arrays explicitly: O(C⋅N).
-
If you stream values and compute mean/variance on the fly (using a two-pass or online algorithm), you can reduce extra space to O(1) besides input storage. For most coding problems, treating it as O(N) input space and O(1) extra space is sufficient.