示例#1
0
    def setUp(self):
        """Initialise the common tests attributes."""

        self._shape = SPECTRAL_SHAPE_OTSU2018
        self._cmfs, self._sd_D65 = handle_spectral_arguments(
            shape_default=self._shape
        )

        self._reflectances = sds_and_msds_to_msds(
            SDS_COLOURCHECKERS["ColorChecker N Ohta"].values()
        )

        self._tree = Tree_Otsu2018(self._reflectances)
        self._tree.optimise()
        for leaf in self._tree.leaves:
            if len(leaf.parent.children) == 2:
                self._node_a = leaf.parent
                self._node_b, self._node_c = self._node_a.children
                break

        self._data_a = Data_Otsu2018(
            np.transpose(reshape_msds(self._reflectances, self._shape).values),
            self._cmfs,
            self._sd_D65,
        )
        self._data_b = self._node_b.data

        self._partition_axis = self._node_a.partition_axis
示例#2
0
    def test_mean(self):
        """Test :attr:`colour.recovery.otsu2018.Data_Otsu2018.mean` property."""

        data = Data_Otsu2018(self._reflectances, self._cmfs, self._sd_D65)

        self.assertIsNone(data.mean)

        data.PCA()

        self.assertTupleEqual(data.mean.shape, (36,))
示例#3
0
    def test_raise_exception_reconstruction_error(self):
        """
        Test :meth:`colour.recovery.otsu2018.Data_Otsu2018.\
reconstruction_error` method raised exception.
        """

        self.assertRaises(
            ValueError,
            Data_Otsu2018(None, self._cmfs, self._sd_D65).reconstruction_error,
        )
示例#4
0
    def test_reconstruction_error(self):
        """
        Test :meth:`colour.recovery.otsu2018.Data_Otsu2018.\
reconstruction_error` method.
        """

        data = Data_Otsu2018(self._reflectances, self._cmfs, self._sd_D65)

        self.assertAlmostEqual(
            data.reconstruction_error(), 2.753352549148681, places=7
        )
示例#5
0
    def test_raise_exception_partition(self):
        """
        Test :meth:`colour.recovery.otsu2018.Data_Otsu2018.partition` method
        raised exception.
        """

        self.assertRaises(
            ValueError,
            Data_Otsu2018(None, self._cmfs, self._sd_D65).partition,
            PartitionAxis(4, 1),
        )
示例#6
0
    def test_raise_exception_origin(self):
        """
        Test :meth:`colour.recovery.otsu2018.Data_Otsu2018.origin` method
        raised exception.
        """

        self.assertRaises(
            ValueError,
            Data_Otsu2018(None, self._cmfs, self._sd_D65).origin,
            4,
            1,
        )
示例#7
0
    def test_basis_functions(self):
        """
        Test :attr:`colour.recovery.otsu2018.Data_Otsu2018.basis_functions`
        property.
        """

        data = Data_Otsu2018(self._reflectances, self._cmfs, self._sd_D65)

        self.assertIsNone(data.basis_functions)

        data.PCA()

        self.assertTupleEqual(data.basis_functions.shape, (3, 36))
示例#8
0
    def setUp(self):
        """Initialise the common tests attributes."""

        self._shape = SPECTRAL_SHAPE_OTSU2018
        self._cmfs, self._sd_D65 = handle_spectral_arguments(
            shape_default=self._shape
        )

        self._reflectances = np.transpose(
            reshape_msds(
                sds_and_msds_to_msds(
                    SDS_COLOURCHECKERS["ColorChecker N Ohta"].values()
                ),
                self._shape,
            ).values
        )

        self._data = Data_Otsu2018(
            self._reflectances, self._cmfs, self._sd_D65
        )
示例#9
0
    def test_reconstruct(self):
        """
        Test :meth:`colour.recovery.otsu2018.Data_Otsu2018.reconstruct`
        method.
        """

        data = Data_Otsu2018(self._reflectances, self._cmfs, self._sd_D65)

        data.PCA()

        np.testing.assert_almost_equal(
            data.reconstruct(
                np.array(
                    [
                        0.20654008,
                        0.12197225,
                        0.05136952,
                    ]
                )
            ).values,
            np.array(
                [
                    0.06899964,
                    0.08241919,
                    0.09768650,
                    0.08938555,
                    0.07872582,
                    0.07140930,
                    0.06385099,
                    0.05471747,
                    0.04281364,
                    0.03073280,
                    0.01761134,
                    0.00772535,
                    0.00379120,
                    0.00405617,
                    0.00595014,
                    0.01323536,
                    0.03229711,
                    0.05661531,
                    0.07763041,
                    0.10271461,
                    0.14276781,
                    0.20239859,
                    0.27288559,
                    0.35044541,
                    0.42170481,
                    0.47567859,
                    0.50910276,
                    0.53578140,
                    0.55251101,
                    0.56530032,
                    0.58029915,
                    0.59367723,
                    0.60830542,
                    0.62100871,
                    0.62881635,
                    0.63971254,
                ]
            ),
            decimal=7,
        )
示例#10
0
    def test_PCA(self):
        """Test :meth:`colour.recovery.otsu2018.Data_Otsu2018.PCA` method."""

        data = Data_Otsu2018(self._reflectances, self._cmfs, self._sd_D65)

        data.PCA()

        np.testing.assert_almost_equal(
            data.basis_functions,
            np.array(
                [
                    [
                        0.04391241,
                        0.08560996,
                        0.15556120,
                        0.20826672,
                        0.22981218,
                        0.23117641,
                        0.22718022,
                        0.21742869,
                        0.19854261,
                        0.16868383,
                        0.12020268,
                        0.05958463,
                        -0.01015508,
                        -0.08775193,
                        -0.16957532,
                        -0.23186776,
                        -0.26516404,
                        -0.27409402,
                        -0.27856619,
                        -0.27685075,
                        -0.25597708,
                        -0.21331000,
                        -0.15372029,
                        -0.08746878,
                        -0.02744494,
                        0.01725581,
                        0.04756055,
                        0.07184639,
                        0.09090063,
                        0.10317253,
                        0.10830387,
                        0.10872694,
                        0.10645999,
                        0.10766424,
                        0.11170078,
                        0.11620896,
                    ],
                    [
                        0.03137588,
                        0.06204234,
                        0.11364884,
                        0.17579436,
                        0.20914074,
                        0.22152351,
                        0.23120105,
                        0.24039823,
                        0.24730359,
                        0.25195045,
                        0.25237533,
                        0.24672212,
                        0.23538236,
                        0.22094141,
                        0.20389065,
                        0.18356599,
                        0.15952882,
                        0.13567812,
                        0.11401807,
                        0.09178015,
                        0.06539517,
                        0.03173809,
                        -0.00658524,
                        -0.04710763,
                        -0.08379987,
                        -0.11074555,
                        -0.12606191,
                        -0.13630094,
                        -0.13988107,
                        -0.14193361,
                        -0.14671866,
                        -0.15164795,
                        -0.15772737,
                        -0.16328073,
                        -0.16588768,
                        -0.16947164,
                    ],
                    [
                        -0.01360289,
                        -0.02375832,
                        -0.04262545,
                        -0.07345243,
                        -0.09081235,
                        -0.09227928,
                        -0.08922710,
                        -0.08626299,
                        -0.08584571,
                        -0.08843734,
                        -0.09475094,
                        -0.10376740,
                        -0.11331399,
                        -0.12109706,
                        -0.12678070,
                        -0.13401030,
                        -0.14417036,
                        -0.15408359,
                        -0.16265529,
                        -0.17079814,
                        -0.17972656,
                        -0.19005983,
                        -0.20053986,
                        -0.21017531,
                        -0.21808806,
                        -0.22347400,
                        -0.22650876,
                        -0.22895376,
                        -0.22982598,
                        -0.23001787,
                        -0.23036398,
                        -0.22917409,
                        -0.22684271,
                        -0.22387883,
                        -0.22065773,
                        -0.21821049,
                    ],
                ]
            ),
            decimal=7,
        )

        np.testing.assert_almost_equal(
            data.mean,
            np.array(
                [
                    0.08795833,
                    0.12050000,
                    0.16787500,
                    0.20675000,
                    0.22329167,
                    0.22837500,
                    0.23229167,
                    0.23579167,
                    0.23658333,
                    0.23779167,
                    0.23866667,
                    0.23975000,
                    0.24345833,
                    0.25054167,
                    0.25791667,
                    0.26150000,
                    0.26437500,
                    0.26566667,
                    0.26475000,
                    0.26554167,
                    0.27137500,
                    0.28279167,
                    0.29529167,
                    0.31070833,
                    0.32575000,
                    0.33829167,
                    0.34675000,
                    0.35554167,
                    0.36295833,
                    0.37004167,
                    0.37854167,
                    0.38675000,
                    0.39587500,
                    0.40266667,
                    0.40683333,
                    0.41287500,
                ]
            ),
            decimal=7,
        )