blob: 62b5020838d135f3ca78faffc454837afa9e33d7 [file] [log] [blame]
Ruben Brunk370e2432014-10-14 18:33:23 -07001# Copyright 2013 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import its.image
16import its.caps
17import its.device
18import its.objects
19import its.target
20import pylab
21import os.path
22import matplotlib
23import matplotlib.pyplot
24
25def main():
26 """Test that the android.noiseReduction.mode param is applied when set.
27
28 Capture images with the camera dimly lit. Uses a high analog gain to
29 ensure the captured image is noisy.
30
31 Captures three images, for NR off, "fast", and "high quality".
32 Also captures an image with low gain and NR off, and uses the variance
33 of this as the baseline.
34 """
35 NAME = os.path.basename(__file__).split(".")[0]
36
37 # List of variances for Y,U,V.
38 variances = [[],[],[]]
39
40 # Reference (baseline) variance for each of Y,U,V.
41 ref_variance = []
42
43 nr_modes_reported = []
44
45 with its.device.ItsSession() as cam:
46 props = cam.get_camera_properties()
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -070047 its.caps.skip_unless(its.caps.compute_target_exposure(props))
Ruben Brunk370e2432014-10-14 18:33:23 -070048
49 # NR mode 0 with low gain
50 e, s = its.target.get_target_exposure_combos(cam)["minSensitivity"]
51 req = its.objects.manual_capture_request(s, e)
52 req["android.noiseReduction.mode"] = 0
53 cap = cam.do_capture(req)
54 its.image.write_image(
55 its.image.convert_capture_to_rgb_image(cap),
56 "%s_low_gain.jpg" % (NAME))
57 planes = its.image.convert_capture_to_planes(cap)
58 for j in range(3):
59 img = planes[j]
60 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
61 ref_variance.append(its.image.compute_image_variances(tile)[0])
62 print "Ref variances:", ref_variance
63
64 for i in range(3):
65 # NR modes 0, 1, 2 with high gain
66 e, s = its.target.get_target_exposure_combos(cam)["maxSensitivity"]
67 req = its.objects.manual_capture_request(s, e)
68 req["android.noiseReduction.mode"] = i
69 cap = cam.do_capture(req)
70 nr_modes_reported.append(
71 cap["metadata"]["android.noiseReduction.mode"])
72 its.image.write_image(
73 its.image.convert_capture_to_rgb_image(cap),
74 "%s_high_gain_nr=%d.jpg" % (NAME, i))
75 planes = its.image.convert_capture_to_planes(cap)
76 for j in range(3):
77 img = planes[j]
78 tile = its.image.get_image_patch(img, 0.45, 0.45, 0.1, 0.1)
79 variance = its.image.compute_image_variances(tile)[0]
80 variances[j].append(variance / ref_variance[j])
81 print "Variances with NR mode [0,1,2]:", variances
82
83 # Draw a plot.
84 for j in range(3):
85 pylab.plot(range(3), variances[j], "rgb"[j])
86 matplotlib.pyplot.savefig("%s_plot_variances.png" % (NAME))
87
88 assert(nr_modes_reported == [0,1,2])
89
90 # Check that the variance of the NR=0 image is higher than for the
91 # NR=1 and NR=2 images.
92 for j in range(3):
93 for i in range(1,3):
94 assert(variances[j][i] < variances[j][0])
95
96if __name__ == '__main__':
97 main()
98