• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
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# ==============================================================================
15"""Tests for python single_image_random_dot_stereograms_ops."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import print_function
20
21from tensorflow.contrib.image.python.ops.single_image_random_dot_stereograms \
22    import single_image_random_dot_stereograms
23from tensorflow.python.framework import constant_op
24from tensorflow.python.framework import test_util
25from tensorflow.python.platform import googletest
26
27class SingleImageRandomDotStereogramsTest(test_util.TensorFlowTestCase):
28
29  def test_shape_function_default(self):
30    """
31    NOTE: The output_image_shape is [X, Y, C]
32    while the output data is [Y, X, C] (or [H, W, C]).
33    As a result, by default the output_image_shape has the value
34    of [1024, 768, 1], but the output data will be [768, 1024, 1].
35    """
36    x_np = [[1, 2, 3, 3, 2, 1],
37            [1, 2, 3, 4, 5, 2],
38            [1, 2, 3, 4, 5, 3],
39            [1, 2, 3, 4, 5, 4],
40            [6, 5, 4, 4, 5, 5]]
41    x_tf = constant_op.constant(x_np)
42    # By default [1024, 768, 1] => [768, 1024, 1].
43    sirds_1 = single_image_random_dot_stereograms(
44        x_tf,
45        convergence_dots_size=8,
46        number_colors=256,
47        normalize=True)
48    shape_1 = sirds_1.get_shape().as_list()
49    self.assertEqual(shape_1, [768, 1024, 1])
50    with self.cached_session():
51      r_tf_1 = sirds_1.eval()
52      self.assertAllEqual(shape_1, r_tf_1.shape)
53
54    # If color > 256 then [1024, 768, 3] => [768, 1024, 3].
55    sirds_2 = single_image_random_dot_stereograms(
56        x_tf,
57        convergence_dots_size=8,
58        number_colors=512,
59        normalize=True)
60    shape_2 = sirds_2.get_shape().as_list()
61    self.assertEqual(shape_2, [768, 1024, 3])
62    with self.cached_session():
63      r_tf_2 = sirds_2.eval()
64      self.assertAllEqual(shape_2, r_tf_2.shape)
65
66    # If explicitly set output_image_shape to [1200, 800, 1],
67    # then the output data should be [800, 1200, 1].
68    sirds_3 = single_image_random_dot_stereograms(
69        x_tf,
70        convergence_dots_size=8,
71        number_colors=256,
72        normalize=True,
73        output_image_shape=[1200, 800, 1])
74    shape_3 = sirds_3.get_shape().as_list()
75    self.assertEqual(shape_3, [800, 1200, 1])
76    with self.cached_session():
77      r_tf_3 = sirds_3.eval()
78      self.assertAllEqual(shape_3, r_tf_3.shape)
79
80
81if __name__ == '__main__':
82  googletest.main()
83