aboutsummaryrefslogtreecommitdiff
path: root/apps/CameraITS/tests/scene1/test_param_noise_reduction.py
diff options
context:
space:
mode:
authorTimothy Knight <tknight@google.com>2014-07-12 00:46:11 -0700
committerTimothy Knight <tknight@google.com>2014-07-12 00:55:49 -0700
commit312c1c3e4faad4e77070059d3b88acd3754daa48 (patch)
tree343d5f1248e30e227c6f1b64307fc473dc373192 /apps/CameraITS/tests/scene1/test_param_noise_reduction.py
parent5e8601829f70fc5aa6e66b9f5a597915ce50e366 (diff)
downloadpdk-312c1c3e4faad4e77070059d3b88acd3754daa48.tar.gz
CameraITS: Restructured test folders to group by scenes.
Change-Id: I3dc66bd44569f4416826d7f23b4e63533058bd3f
Diffstat (limited to 'apps/CameraITS/tests/scene1/test_param_noise_reduction.py')
-rw-r--r--apps/CameraITS/tests/scene1/test_param_noise_reduction.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/apps/CameraITS/tests/scene1/test_param_noise_reduction.py b/apps/CameraITS/tests/scene1/test_param_noise_reduction.py
new file mode 100644
index 0000000..d183630
--- /dev/null
+++ b/apps/CameraITS/tests/scene1/test_param_noise_reduction.py
@@ -0,0 +1,102 @@
+# Copyright 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import its.image
+import its.device
+import its.objects
+import pylab
+import os.path
+import matplotlib
+import matplotlib.pyplot
+
+def main():
+ """Test that the android.noiseReduction.mode param is applied when set.
+
+ Capture images with the camera dimly lit. Uses a long exposure
+ and a high analog gain to ensure the captured image is noisy.
+
+ Captures three images, for NR off, "fast", and "high quality".
+ Also captures an image with low gain and NR off, and uses the variance
+ of this as the baseline.
+ """
+ NAME = os.path.basename(__file__).split(".")[0]
+
+ THRESHOLD_MIN_VARIANCE_RATIO = 0.7
+
+ req = {
+ "android.control.mode": 0,
+ "android.control.aeMode": 0,
+ "android.control.awbMode": 0,
+ "android.control.afMode": 0,
+ "android.sensor.frameDuration": 0
+ }
+
+ # List of variances for Y,U,V.
+ variances = [[],[],[]]
+
+ # Reference (baseline) variance for each of Y,U,V.
+ ref_variance = []
+
+ nr_modes_reported = []
+
+ with its.device.ItsSession() as cam:
+ # NR mode 0 with low gain
+ req["android.noiseReduction.mode"] = 0
+ req["android.sensor.sensitivity"] = 100
+ req["android.sensor.exposureTime"] = 20*1000*1000
+ cap = cam.do_capture(req)
+ its.image.write_image(
+ its.image.convert_capture_to_rgb_image(cap),
+ "%s_low_gain.jpg" % (NAME))
+ planes = its.image.convert_capture_to_planes(cap)
+ for j in range(3):
+ img = planes[j]
+ tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
+ ref_variance.append(its.image.compute_image_variances(tile)[0])
+
+ for i in range(3):
+ # NR modes 0, 1, 2 with high gain
+ req["android.noiseReduction.mode"] = i
+ req["android.sensor.sensitivity"] = 100*16
+ req["android.sensor.exposureTime"] = (20*1000*1000/16)
+ cap = cam.do_capture(req)
+ nr_modes_reported.append(
+ cap["metadata"]["android.noiseReduction.mode"])
+ its.image.write_image(
+ its.image.convert_capture_to_rgb_image(cap),
+ "%s_high_gain_nr=%d.jpg" % (NAME, i))
+ planes = its.image.convert_capture_to_planes(cap)
+ for j in range(3):
+ img = planes[j]
+ tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
+ variance = its.image.compute_image_variances(tile)[0]
+ variances[j].append(variance / ref_variance[j])
+
+ # Draw a plot.
+ for j in range(3):
+ pylab.plot(range(3), variances[j], "rgb"[j])
+ matplotlib.pyplot.savefig("%s_plot_variances.png" % (NAME))
+
+ assert(nr_modes_reported == [0,1,2])
+
+ # Check that the variance of the NR=0 image is much higher than for the
+ # NR=1 and NR=2 images.
+ for j in range(3):
+ for i in range(1,3):
+ assert(variances[j][i] / variances[j][0] <
+ THRESHOLD_MIN_VARIANCE_RATIO)
+
+if __name__ == '__main__':
+ main()
+