Beispiel #1
0
    def test__setattr__(self):
        """
        Tests :attr:`colour_hdri.utilities.image.ImageStack.__getattr__`
        method.
        """

        image_stack = ImageStack().from_files(self._test_jpg_images)

        self.assertTupleEqual(image_stack.data.shape, (426, 640, 3, 3))

        image_stack.data = np.random.random((20, 10, 3, 3))

        self.assertTupleEqual(image_stack.data.shape, (20, 10, 3, 3))

        np.testing.assert_almost_equal(
            image_stack.f_number, np.array([8, 8, 8]), decimal=7)

        image_stack.f_number = np.array([1, 2, 3])

        np.testing.assert_almost_equal(
            image_stack.f_number, np.array([1, 2, 3]), decimal=7)

        self.assertEqual(image_stack[0].metadata.f_number, 1)

        self.assertListEqual(list(image_stack.black_level), [None, None, None])

        image_stack.black_level = np.array([2048, 2048, 2048])

        np.testing.assert_almost_equal(
            image_stack.black_level, np.array([2048, 2048, 2048]), decimal=7)

        self.assertEqual(image_stack[0].metadata.black_level, 2048)
Beispiel #2
0
    def test_radiance_image(self):
        """
        Tests :func:`colour_hdri.generation.\
radiance.image_stack_to_radiance_image` definition.
        """

        image_stack = ImageStack.from_files(JPG_IMAGES)
        image_stack.data = RGB_COLOURSPACES['sRGB'].cctf_decoding(
            image_stack.data)

        # Lower precision for unit tests under *travis-ci*.
        np.testing.assert_allclose(image_stack_to_radiance_image(image_stack),
                                   np.load(
                                       os.path.join(
                                           GENERATION_DIRECTORY,
                                           'test_radiance_image_linear.npy')),
                                   rtol=0.0001,
                                   atol=0.0001)

        # Lower precision for unit tests under *travis-ci*.
        image_stack = ImageStack.from_files(JPG_IMAGES)
        np.testing.assert_allclose(image_stack_to_radiance_image(
            image_stack,
            camera_response_functions=(
                camera_response_functions_Debevec1997(image_stack))),
                                   np.load(
                                       os.path.join(
                                           GENERATION_DIRECTORY,
                                           'test_radiance_image_crfs.npy')),
                                   rtol=0.0001,
                                   atol=0.0001)
    def test__setattr__(self):
        """
        Tests :attr:`colour_hdri.utilities.image.ImageStack.__getattr__`
        method.
        """

        image_stack = ImageStack().from_files(self.__test_jpg_images)

        self.assertTupleEqual(image_stack.data.shape, (426, 640, 3, 3))

        image_stack.data = np.random.random((20, 10, 3, 3))

        self.assertTupleEqual(image_stack.data.shape, (20, 10, 3, 3))

        np.testing.assert_almost_equal(image_stack.f_number, np.array([8.0, 8.0, 8.0]), decimal=7)

        image_stack.f_number = np.array([1, 2, 3])

        np.testing.assert_almost_equal(image_stack.f_number, np.array([1, 2, 3]), decimal=7)

        self.assertEqual(image_stack[0].metadata.f_number, 1)

        self.assertListEqual(list(image_stack.black_level), [None, None, None])

        image_stack.black_level = np.array([2048, 2048, 2048])

        np.testing.assert_almost_equal(image_stack.black_level, np.array([2048, 2048, 2048]), decimal=7)

        self.assertEqual(image_stack[0].metadata.black_level, 2048)
    def test_radiance_image(self):
        """
        Tests :func:`colour_hdri.generation.\
radiance.image_stack_to_radiance_image` definition.
        """

        image_stack = ImageStack.from_files(JPG_IMAGES)
        image_stack.data = RGB_COLOURSPACES['sRGB'].EOCF(
            image_stack.data)
        np.testing.assert_almost_equal(
            image_stack_to_radiance_image(image_stack),
            np.load(os.path.join(
                GENERATION_DIRECTORY,
                'test_radiance_image_linear.npy')),
            decimal=7)

        # Lower precision for unit tests under *travis-ci*.
        image_stack = ImageStack.from_files(JPG_IMAGES)
        np.testing.assert_allclose(
            image_stack_to_radiance_image(
                image_stack,
                camera_response_functions=(
                    camera_response_functions_Debevec1997(image_stack))),
            np.load(os.path.join(
                GENERATION_DIRECTORY,
                'test_radiance_image_crfs.npy')),
            rtol=0.00001,
            atol=0.00001)
Beispiel #5
0
    def test__setitem__(self):
        """
        Tests :attr:`colour_hdri.utilities.image.ImageStack.__setitem__`
        method.
        """

        image_stack = ImageStack()
        image = Image(self._test_jpg_images[0])
        image.read_data()
        image.read_metadata()
        image_stack.insert(0, image)

        self.assertEqual(image_stack[0], image)
    def test__setitem__(self):
        """
        Tests :attr:`colour_hdri.utilities.image.ImageStack.__setitem__`
        method.
        """

        image_stack = ImageStack()
        image = Image(self.__test_jpg_images[0])
        image.read_data()
        image.read_metadata()
        image_stack.insert(0, image)

        self.assertEqual(image_stack[0], image)
    def test_g_solve(self):
        """
        Tests :func:`colour_hdri.calibration.debevec1997.g_solve` definition.
        """

        image_stack = ImageStack.from_files(JPG_IMAGES)
        L_l = np.log(average_luminance(image_stack.f_number,
                                       image_stack.exposure_time,
                                       image_stack.iso))
        samples = samples_Grossberg2003(image_stack.data)

        for i in range(3):
            g, lE = g_solve(samples[..., i], L_l)

            # Lower precision for unit tests under *travis-ci*.
            np.testing.assert_allclose(
                g[0:-2],
                np.load(os.path.join(
                    CALIBRATION_DIRECTORY,
                    'test_g_solve_g_{0}.npy'.format(i)))[0:-2],
                rtol=0.001,
                atol=0.001)

            # Lower precision for unit tests under *travis-ci*.
            np.testing.assert_allclose(
                lE[1:],
                np.load(os.path.join(
                    CALIBRATION_DIRECTORY,
                    'test_g_solve_lE_{0}.npy'.format(i)))[1:],
                rtol=0.001,
                atol=0.001)
    def test_g_solve(self):
        """
        Tests :func:`colour_hdri.calibration.debevec1997.g_solve` definition.
        """

        image_stack = ImageStack.from_files(JPG_IMAGES)
        L_l = np.log(1 / average_luminance(
            image_stack.f_number, image_stack.exposure_time, image_stack.iso))
        samples = samples_Grossberg2003(image_stack.data)

        for i in range(3):
            g, lE = g_solve(samples[..., i], L_l)

            # Lower precision for unit tests under *travis-ci*.
            np.testing.assert_allclose(
                g[0:-2],
                np.load(
                    os.path.join(CALIBRATION_DIRECTORY,
                                 'test_g_solve_g_{0}.npy'.format(i)))[0:-2],
                rtol=0.001,
                atol=0.001)

            # Lower precision for unit tests under *travis-ci*.
            np.testing.assert_allclose(
                lE[1:],
                np.load(
                    os.path.join(CALIBRATION_DIRECTORY,
                                 'test_g_solve_lE_{0}.npy'.format(i)))[1:],
                rtol=0.001,
                atol=0.001)
Beispiel #9
0
    def test_from_files(self):
        """
        Tests :attr:`colour_hdri.utilities.image.ImageStack.test_from_files`
        method.
        """

        image_stack = ImageStack().from_files(reversed(self._test_jpg_images))
        self.assertListEqual(list(image_stack.path), self._test_jpg_images)
Beispiel #10
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._test_jpg_images = filter_files(FROBISHER_001_DIRECTORY,
                                             ('jpg', ))

        self._image_stack = ImageStack().from_files(self._test_jpg_images)
Beispiel #11
0
    def test__delitem__(self):
        """
        Tests :attr:`colour_hdri.utilities.image.ImageStack.__delitem__`
        method.
        """

        image_stack = ImageStack().from_files(self._test_jpg_images)

        del image_stack[0]

        self.assertEqual(len(image_stack), 2)
Beispiel #12
0
    def test_samples_Grossberg2003(self):
        """
        Tests :func:`colour_hdri.sampling.grossberg2003.\
samples_Grossberg2003` definition.
        """

        np.testing.assert_almost_equal(
            samples_Grossberg2003(ImageStack.from_files(JPG_IMAGES).data),
            np.load(
                os.path.join(SAMPLING_DIRECTORY,
                             'test_samples_Grossberg2003.npy')),
            decimal=7)
    def test_samples_Grossberg2003(self):
        """
        Tests :func:`colour_hdri.sampling.grossberg2003.\
samples_Grossberg2003` definition.
        """

        np.testing.assert_almost_equal(
            samples_Grossberg2003(ImageStack.from_files(JPG_IMAGES).data),
            np.load(os.path.join(
                SAMPLING_DIRECTORY,
                'test_samples_Grossberg2003.npy')),
            decimal=7)
    def test_camera_response_function_Debevec1997(self):
        """
        Tests :func:`colour_hdri.calibration.debevec1997.\
camera_response_functions_Debevec1997` definition.
        """

        # Lower precision for unit tests under *travis-ci*.
        np.testing.assert_allclose(
            camera_response_functions_Debevec1997(
                ImageStack.from_files(JPG_IMAGES)),
            np.load(os.path.join(
                CALIBRATION_DIRECTORY,
                'test_camera_response_function_Debevec1997_crfs.npy')),
            rtol=0.00001,
            atol=0.00001)
    def test_camera_response_function_Debevec1997(self):
        """
        Tests :func:`colour_hdri.calibration.debevec1997.\
camera_response_functions_Debevec1997` definition.
        """

        # Lower precision for unit tests under *travis-ci*.
        np.testing.assert_allclose(
            camera_response_functions_Debevec1997(
                ImageStack.from_files(JPG_IMAGES)),
            np.load(
                os.path.join(
                    CALIBRATION_DIRECTORY,
                    'test_camera_response_function_Debevec1997_crfs.npy')),
            rtol=0.00001,
            atol=0.00001)