Skip to content

Commit

Permalink
Merge branch 'feature/zhao2009' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Nov 30, 2020
2 parents 026edc5 + bfee1a4 commit b1cb83e
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 4 deletions.
23 changes: 23 additions & 0 deletions BIBLIOGRAPHY.bib
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,26 @@ @misc{X-Rite2016
url = {http://xritephoto.com/ph_product_overview.aspx?ID=938\&Action=Support\&SupportID=5884\#},
urldate = {2018-10-29},
}
@article{Zhao2009,
title = {Estimating basis functions for spectral sensitivity
of digital cameras},
author = {Zhao, Hongxun and Kawakami, Rei and Tan, Robby T and
Ikeuchi, Katsushi},
year = 2009,
pages = 7,
abstract = {Spectral sensitivity of digital cameras plays an
important role for many computer vision applications. However,
less attention has been drawn on estimating the spectral
sensitivity of commercial cameras, and there is neither
comprehensive analysis of those spectral characteristics. This
paper investigates the characteristics by extracting the basis
functions of them by using SVD (Singular Value Decomposition); we
have collected data from the literature but also by measuring the
sensitivity of different cameras. This paper compares the
extracted basis functions with different mathematical basis
functions and obtains the optimum set of basis functions. The
extracted basis functions can be used to estimate the unknown
spectral sensitivity of an arbitrary camera.},
keywords = {⛔ No DOI found},
language = {en},
}
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ definition:
colour-science-datasets
=======================

Datasets : 18
Datasets : 19
Synced : 1
URL : https://zenodo.org/communities/colour-science-datasets/

Datasets
--------

[ ] 4050598 : Spectral Upsampling Coefficient Tables - Jakob and Hanika (2019)
[ ] 3269926 : Agfa IT8.7/2 Set - Marszalec (n.d.)
[ ] 3245883 : Camera Spectral Sensitivity Database - Jiang et al. (2013)
[ ] 3367463 : Constant Hue Loci Data - Hung and Berns (1995)
Expand All @@ -151,6 +150,8 @@ definition:
[ ] 3252742 : Observer Function Database - Asano (2015)
[ ] 3269922 : Paper Spectra - Haanpalo (n.d.)
[ ] 3372171 : RAW to ACES Utility Data - Dyer et al. (2017)
[ ] 4297288 : Spectral Sensitivity Database - Zhao et al. (2009)
[ ] 4050598 : Spectral Upsampling Coefficient Tables - Jakob and Hanika. (2019)

A ticked checkbox means that the particular dataset has been synced locally.
A dataset is loaded by using its unique number: *3245895*:
Expand Down
3 changes: 3 additions & 0 deletions colour_datasets/loaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .labsphere2019 import DatasetLoader_Labsphere2019, build_Labsphere2019
from .luo1999 import DatasetLoader_Luo1999, build_Luo1999
from .xrite2016 import DatasetLoader_XRite2016, build_XRite2016
from .zhao2009 import DatasetLoader_Zhao2009, build_Zhao2009

__all__ = ['AbstractDatasetLoader']
__all__ += ['DatasetLoader_Asano2015', 'build_Asano2015']
Expand All @@ -32,6 +33,7 @@
__all__ += ['DatasetLoader_Labsphere2019', 'build_Labsphere2019']
__all__ += ['DatasetLoader_Luo1999', 'build_Luo1999']
__all__ += ['DatasetLoader_XRite2016', 'build_XRite2016']
__all__ += ['DatasetLoader_Zhao2009', 'build_Zhao2009']

DATASET_LOADERS = CaseInsensitiveMapping({
DatasetLoader_Asano2015.ID: build_Asano2015,
Expand All @@ -44,6 +46,7 @@
DatasetLoader_Labsphere2019.ID: build_Labsphere2019,
DatasetLoader_Luo1999.ID: build_Luo1999,
DatasetLoader_XRite2016.ID: build_XRite2016,
DatasetLoader_Zhao2009.ID: build_Zhao2009,
})
DATASET_LOADERS.__doc__ = """
Dataset loaders ids and callables.
Expand Down
84 changes: 84 additions & 0 deletions colour_datasets/loaders/tests/test_zhao2009.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
"""
Defines unit tests for :mod:`colour_datasets.loaders.zhao2009` module.
"""

from __future__ import division, unicode_literals

import unittest

from colour import SpectralShape

from colour_datasets.loaders import DatasetLoader_Zhao2009, build_Zhao2009

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2019-2020 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = 'colour-developers@colour-science.org'
__status__ = 'Production'

__all__ = ['TestDatasetLoader_Zhao2009', 'TestBuildZhao2009']


class TestDatasetLoader_Zhao2009(unittest.TestCase):
"""
Defines :class:`colour_datasets.loaders.zhao2009.DatasetLoader_Zhao2009`
class unit tests methods.
"""

def test_required_attributes(self):
"""
Tests presence of required attributes.
"""

required_attributes = ('ID', )

for attribute in required_attributes:
self.assertIn(attribute, dir(DatasetLoader_Zhao2009))

def test_required_methods(self):
"""
Tests presence of required methods.
"""

required_methods = ('__init__', 'load')

for method in required_methods:
self.assertIn(method, dir(DatasetLoader_Zhao2009))

def test_load(self):
"""
Tests :func:`colour_datasets.loaders.zhao2009.\
DatasetLoader_Zhao2009.load` method.
"""

dataset = DatasetLoader_Zhao2009()
self.assertEqual(
sorted(dataset.load().keys()),
sorted([
'SONY DXC 930', 'KODAK DCS 420', 'NIKON D1X', 'SONY DXC 9000',
'CANON 10D', 'NIKON D70', 'KODAK DCS 460', 'CANON 400D',
'CANON 5D', 'CANON 5D Mark 2', 'Ladybug2', 'KODAK DCS 200'
]))
self.assertEqual(dataset.content['SONY DXC 930'].shape,
SpectralShape(400, 700, 4))


class TestBuildZhao2009(unittest.TestCase):
"""
Defines :func:`colour_datasets.loaders.zhao2009.build_Zhao2009`
definition unit tests methods.
"""

def test_build_Zhao2009(self):
"""
Tests :func:`colour_datasets.loaders.zhao2009.build_Zhao2009`
definition.
"""

self.assertIs(build_Zhao2009(), build_Zhao2009())


if __name__ == '__main__':
unittest.main()
157 changes: 157 additions & 0 deletions colour_datasets/loaders/zhao2009.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# -*- coding: utf-8 -*-
"""
Spectral Sensitivity Database - Zhao et al. (2009)
==================================================
Defines the objects implementing support for *Zhao, Kawakami, Tan and Ikeuchi
(2009)* *Spectral Sensitivity Database* dataset loading:
- :class:`colour_datasets.loaders.DatasetLoader_Zhao2009`
- :func:`colour_datasets.loaders.build_Zhao2009`
References
----------
- :cite:`Zhao2009` : Zhao, H., Kawakami, R., Tan, R. T., & Ikeuchi, K.
(2009). Estimating basis functions for spectral sensitivity of digital
cameras. 7.
"""

from __future__ import division, unicode_literals

import numpy as np
import os
from collections import OrderedDict

from colour.characterisation import RGB_CameraSensitivities

from colour_datasets.records import datasets
from colour_datasets.loaders import AbstractDatasetLoader

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2019-2020 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = 'colour-developers@colour-science.org'
__status__ = 'Production'

__all__ = ['DatasetLoader_Zhao2009', 'build_Zhao2009']


class DatasetLoader_Zhao2009(AbstractDatasetLoader):
"""
Defines the *Zhao et al. (2009)* *Spectral Sensitivity Database*
dataset loader.
Attributes
----------
- :attr:`colour_datasets.loaders.DatasetLoader_Zhao2009.ID`
Methods
-------
- :meth:`colour_datasets.loaders.DatasetLoader_Zhao2009.__init__`
- :meth:`colour_datasets.loaders.DatasetLoader_Zhao2009.load`
References
----------
:cite:`Zhao2009`
"""

ID = '4297288'
"""
Dataset record id, i.e. the *Zenodo* record number.
ID : unicode
"""

def __init__(self):
super(DatasetLoader_Zhao2009,
self).__init__(datasets()[DatasetLoader_Zhao2009.ID])

def load(self):
"""
Syncs, parses, converts and returns the *Zhao et al. (2009)*
*Spectral Sensitivity Database* dataset content.
Returns
-------
OrderedDict
*Zhao et al. (2009)* *Spectral Sensitivity Database*
dataset content.
Examples
--------
>>> from colour_datasets.utilities import suppress_stdout
>>> dataset = DatasetLoader_Zhao2009()
>>> with suppress_stdout():
... dataset.load()
>>> len(dataset.content.keys())
12
"""

super(DatasetLoader_Zhao2009, self).sync()

cameras = [
'SONY DXC 930',
'KODAK DCS 420',
'NIKON D1X',
'SONY DXC 9000',
'CANON 10D',
'NIKON D70',
'KODAK DCS 460',
'CANON 400D',
'CANON 5D',
'CANON 5D Mark 2',
'Ladybug2',
'KODAK DCS 200',
]

self._content = OrderedDict()

for i, camera in enumerate(cameras):
data = np.loadtxt(
os.path.join(self.record.repository, 'dataset',
'camera_{0}.spectra'.format(i)))
self._content[camera] = RGB_CameraSensitivities(
data[..., 1:], data[..., 0], name=camera)

return self._content


_DATASET_LOADER_JIANG2009 = None
"""
Singleton instance of the *Zhao et al. (2009)*
*Spectral Sensitivity Database* dataset loader.
_DATASET_LOADER_JIANG2009 : DatasetLoader_Zhao2009
"""


def build_Zhao2009(load=True):
"""
Singleton factory that builds the *Zhao et al. (2009)*
*Spectral Sensitivity Database* dataset loader.
Parameters
----------
load : bool, optional
Whether to load the dataset upon instantiation.
Returns
-------
DatasetLoader_Zhao2009
Singleton instance of the *Zhao et al. (2009)*
*Spectral Sensitivity Database* dataset loader.
References
----------
:cite:`Zhao2009`
"""

global _DATASET_LOADER_JIANG2009

if _DATASET_LOADER_JIANG2009 is None:
_DATASET_LOADER_JIANG2009 = DatasetLoader_Zhao2009()
if load:
_DATASET_LOADER_JIANG2009.load()

return _DATASET_LOADER_JIANG2009
14 changes: 14 additions & 0 deletions docs/colour_datasets.loaders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,17 @@ RAW to ACES Utility Data - Dyer et al. (2017)
:toctree: generated/

build_Dyer2017

Spectral Sensitivity Database - Zhao et al. (2009)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
:toctree: generated/
:template: class.rst

DatasetLoader_Zhao2009

.. autosummary::
:toctree: generated/

build_Zhao2009
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ definition:
colour-science-datasets
=======================

Datasets : 18
Datasets : 19
Synced : 1
URL : https://zenodo.org/communities/colour-science-datasets/

Datasets
--------

[ ] 4050598 : Spectral Upsampling Coefficient Tables - Jakob and Hanika (2019)
[ ] 3269926 : Agfa IT8.7/2 Set - Marszalec (n.d.)
[ ] 3245883 : Camera Spectral Sensitivity Database - Jiang et al. (2013)
[ ] 3367463 : Constant Hue Loci Data - Hung and Berns (1995)
Expand All @@ -146,6 +145,8 @@ definition:
[ ] 3252742 : Observer Function Database - Asano (2015)
[ ] 3269922 : Paper Spectra - Haanpalo (n.d.)
[ ] 3372171 : RAW to ACES Utility Data - Dyer et al. (2017)
[ ] 4297288 : Spectral Sensitivity Database - Zhao et al. (2009)
[ ] 4050598 : Spectral Upsampling Coefficient Tables - Jakob and Hanika. (2019)

A ticked checkbox means that the particular dataset has been synced locally.
A dataset is loaded by using its unique number: *3245895*:
Expand Down

0 comments on commit b1cb83e

Please sign in to comment.