Skip to content

Commit

Permalink
Implement support for "Hung and Berns (1995)" "Constant Hue Loci Data".
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Aug 13, 2019
1 parent ba8ced7 commit deda9ea
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 29 deletions.
54 changes: 27 additions & 27 deletions BIBLIOGRAPHY.bib
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,52 @@ @inproceedings{Ebner1998
url = {http:https://proceedings.spiedigitallibrary.org/proceeding.aspx?articleid=936964},
year = 1998,
}
@misc{Haanpaloa,
author = {Haanpalo, Jouni and {University of Kuopio}},
doi = {10.5281/zenodo.3269922},
title = {{Paper Spectra}},
url = {http:https://www.uef.fi/web/spectral/paper-spectra},
}
@misc{Haanpalo,
author = {Haanpalo, Jouni and {University of Kuopio}},
doi = {10.5281/zenodo.3269916},
title = {{Munsell Colors Glossy (Spectrofotometer Measured)}},
url = {http:https://www.uef.fi/web/spectral/munsell-colors-glossy-spectrofotometer-measured},
}
@misc{Hauta-Kasaria,
author = {Hauta-Kasari, Markku and {University of Kuopio}},
doi = {10.5281/zenodo.3269914},
title = {{Munsell Colors Matt (AOTF Measured)}},
url = {http:https://www.uef.fi/web/spectral/munsell-colors-matt-aotf-measured-},
@misc{Haanpaloa,
author = {Haanpalo, Jouni and {University of Kuopio}},
doi = {10.5281/zenodo.3269922},
title = {{Paper Spectra}},
url = {http:https://www.uef.fi/web/spectral/paper-spectra},
}
@misc{Hauta-Kasari,
author = {Hauta-Kasari, Markku and {University of Kuopio}},
doi = {10.5281/zenodo.3269912},
title = {{Munsell Colors Matt (Spectrofotometer Measured)}},
url = {http:https://www.uef.fi/web/spectral/munsell-colors-matt-spectrofotometer-measured},
}
@misc{Hauta-Kasaria,
author = {Hauta-Kasari, Markku and {University of Kuopio}},
doi = {10.5281/zenodo.3269914},
title = {{Munsell Colors Matt (AOTF Measured)}},
url = {http:https://www.uef.fi/web/spectral/munsell-colors-matt-aotf-measured-},
}
@misc{Hiltunen,
author = {Hiltunen, Jouni and {University of Kuopio}},
doi = {10.5281/zenodo.3269924},
title = {{Lumber Spectra}},
url = {http:https://www.uef.fi/web/spectral/lumber-spectra},
}
@article{Hung1995,
author = {Hung, Po-Chieh and Berns, Roy S.},
doi = {10.1002/col.5080200506},
issn = 03612317,
journal = {Color Research \& Application},
keywords = {color appearance spaces,experiments to evaluate
color space hue linearity,perceived hue},
month = oct,
number = 5,
pages = {285--295},
title = {{Determination of constant Hue Loci for a CRT gamut
and their predictions using color appearance spaces}},
url = {http:https://doi.wiley.com/10.1002/col.5080200506},
volume = 20,
year = 1995,
}
@inproceedings{Jiang2013,
abstract = {Camera spectral sensitivity functions relate scene
radiance with captured RGB triplets. They are important for many
Expand Down Expand Up @@ -176,22 +192,6 @@ @misc{Marszalec
title = {{Agfa IT8.7/2 Set}},
url = {http:https://www.uef.fi/web/spectral/agfa-it8.7/2-set},
}
@article{McCann1976,
author = {McCann, John J. and McKee, Suzanne P. and Taylor,
Thomas H},
doi = {10.1016/0042-6989(76)90020-1},
issn = 00426989,
journal = {Vision Research},
month = jan,
number = 5,
pages = {445--IN3},
title = {{Quantitative studies in retinex theory a comparison
between theoretical predictions and observer responses to the
“color mondrian” experiments}},
url = {https://linkinghub.elsevier.com/retrieve/pii/0042698976900201},
volume = 16,
year = 1976,
}
@misc{OpenpyxlDevelopers2019,
author = {{Openpyxl Developers}},
title = {openpyxl},
Expand Down
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ definition:
colour-science-datasets
=======================

Datasets : 14
Datasets : 15
Synced : 1
URL : https://zenodo.org/communities/colour-science-datasets/

Expand All @@ -142,6 +142,7 @@ definition:

[ ] 3269926 : Agfa IT8.7/2 Set
[ ] 3245883 : Camera Spectral Sensitivity Database
[ ] 3367463 : Constant Hue Loci Data
[ ] 3362536 : Constant Perceived-Hue Data
[ ] 3270903 : Corresponding-Colour Datasets
[ ] 3269920 : Forest Colors
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 @@ -12,6 +12,7 @@
from .abstract import AbstractDatasetLoader
from .asano2015 import Asano2015DatasetLoader, build_Asano2015
from .ebner1998 import Ebner1998DatasetLoader, build_Ebner1998
from .hung1995 import Hung1995DatasetLoader, build_Hung1995
from .jiang2013 import Jiang2013DatasetLoader, build_Jiang2013
from .labsphere2019 import Labsphere2019DatasetLoader, build_Labsphere2019
from .luo1999 import Luo1999DatasetLoader, build_Luo1999
Expand All @@ -20,6 +21,7 @@
__all__ = ['AbstractDatasetLoader']
__all__ += ['Asano2015DatasetLoader', 'build_Asano2015']
__all__ += ['Ebner1998DatasetLoader', 'build_Ebner1998']
__all__ += ['Hung1995DatasetLoader', 'build_Hung1995']
__all__ += ['Jiang2013DatasetLoader', 'build_Jiang2013']
__all__ += ['Jiang2013DatasetLoader', 'build_Jiang2013']
__all__ += ['Labsphere2019DatasetLoader', 'build_Labsphere2019']
Expand All @@ -29,6 +31,7 @@
DATASET_LOADERS = CaseInsensitiveMapping({
Asano2015DatasetLoader.ID: build_Asano2015,
Ebner1998DatasetLoader.ID: build_Ebner1998,
Hung1995DatasetLoader.ID: build_Hung1995,
Jiang2013DatasetLoader.ID: build_Jiang2013,
Labsphere2019DatasetLoader.ID: build_Labsphere2019,
Luo1999DatasetLoader.ID: build_Luo1999,
Expand Down
223 changes: 223 additions & 0 deletions colour_datasets/loaders/hung1995.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# -*- coding: utf-8 -*-
"""
Constant Hue Loci Data - Hung and Berns (1995)
==============================================
Defines the objects implementing support for *Hung and Berns (1995)*
*Constant Hue Loci Data* dataset loading:
- :class:`colour_datasets.loaders.Hung1995DatasetLoader`
- :func:`colour_datasets.loaders.build_Hung1995`
References
----------
- :cite:`Hung1995` : Hung, P.-C., & Berns, R. S. (1995). Determination of
constant Hue Loci for a CRT gamut and their predictions using color
appearance spaces. Color Research & Application, 20(5), 285–295.
doi:10.1002/col.5080200506
"""

from __future__ import division, unicode_literals

import numpy as np
import os
from collections import OrderedDict, namedtuple

from colour import ILLUMINANTS, xy_to_XYZ, xyY_to_XYZ

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

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2019 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = '[email protected]'
__status__ = 'Production'

__all__ = [
'ConstantPerceivedHueColourMatchesHung1995', 'Hung1995DatasetLoader',
'build_Hung1995'
]


class ConstantPerceivedHueColourMatchesHung1995(
namedtuple('ConstantPerceivedHueColourMatchesHung1995',
('name', 'XYZ_r', 'XYZ_cr', 'XYZ_ct', 'metadata'))):
"""
Defines *Hung and Berns (1995)* *Constant Hue Loci Data*
colour matches data for a given hue angle.
Parameters
----------
name : unicode
*Hung and Berns (1995)* *Constant Hue Loci Data* hue angle or
name.
XYZ_r : array_like
*CIE XYZ* tristimulus values of the reference illuminant.
XYZ_cr : array_like
*CIE XYZ* tristimulus values of the reference colour under the
reference illuminant.
XYZ_ct : array_like
*CIE XYZ* tristimulus values of the colour matches under the reference
illuminant.
metadata : dict
Dataset metadata.
"""


class Hung1995DatasetLoader(AbstractDatasetLoader):
"""
Defines the *Hung and Berns (1995)* *Constant Hue Loci Data*
dataset loader.
Attributes
----------
ID
Methods
-------
load
References
----------
:cite:`Hung1995`
"""

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

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

def load(self):
"""
Syncs, parses, converts and returns the *Hung and Berns (1995)*
*Constant Hue Loci Data* dataset content.
Returns
-------
OrderedDict
Dataset content as an :class:`OrderedDict` of :class:`OrderedDict`
of hue and their colour matches data.
Examples
--------
>>> from colour_datasets.utilities import suppress_stdout
>>> dataset = Hung1995DatasetLoader()
>>> with suppress_stdout():
... dataset.load()
>>> len(dataset.data.keys())
6
"""

super(Hung1995DatasetLoader, self).sync()

self._data = OrderedDict()

filenames = OrderedDict([
('Table I.csv', 'Reference colors.'),
('Table II.csv', 'Intra- and interobserver variances for each '
'reference hue expressed in circumferential '
'hue-angle difference.'),
('Table III.csv', 'Weight-averaged constant hue loci for the CL '
'experiment.'),
('Table IV.csv', 'Weight-averaged constant hue loci for the VL '
'experiment.'),
])

for filename in filenames:
datafile_path = os.path.join(self.record.repository, 'dataset',
filename)

self._data[filename.split('.')[0]] = np.genfromtxt(
datafile_path,
delimiter=',',
names=True,
dtype=None,
encoding='utf-8')

hues = [
'Red', 'Red-yellow', 'Yellow', 'Yellow-green', 'Green',
'Green-cyan', 'Cyan', 'Cyan-blue', 'Blue', 'Blue-magenta',
'Magenta', 'Magenta-red'
]

XYZ_r = xy_to_XYZ(
ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['C'])

for table, experiment in [('Table III', 'CL'), ('Table IV', 'VL')]:
key = 'Constant Hue Loci - {0}'.format(experiment)
self._data[key] = OrderedDict()
for hue in hues:
for sample_r in self._data['Table I']:
sample_r = sample_r.tolist()
if sample_r[0] == hue:
XYZ_cr = xyY_to_XYZ(sample_r[1:4]) / 100
break

XYZ_ct = []
metadata = {
'Color name': [],
'C*uv': [],
}
for sample_t in self._data[table]:
sample_t = sample_t.tolist()
if not sample_t[0] == hue:
continue

XYZ_ct.append(sample_t[2:])
metadata['Color name'].append(sample_t[0])
metadata['C*uv'].append(sample_t[1])

self._data[key][hue] = (
ConstantPerceivedHueColourMatchesHung1995(
hue, XYZ_r, XYZ_cr,
np.vstack(XYZ_ct) / 100, metadata))

return self._data


_HUNG1995_DATASET_LOADER = None
"""
Singleton instance of the *Hung and Berns (1995)*
*Constant Hue Loci Data* dataset loader.
_HUNG1995_DATASET_LOADER : Hung1995DatasetLoader
"""


def build_Hung1995(load=True):
"""
Singleton factory that builds the *Hung and Berns (1995)*
*Constant Hue Loci Data* dataset loader.
Parameters
----------
load : bool, optional
Whether to load the dataset upon instantiation.
Returns
-------
Hung1995DatasetLoader
Singleton instance of the *Hung and Berns (1995)*
*Constant Hue Loci Data* dataset loader.
References
----------
:cite:`Hung1995`
"""

global _HUNG1995_DATASET_LOADER

if _HUNG1995_DATASET_LOADER is None:
_HUNG1995_DATASET_LOADER = Hung1995DatasetLoader()
if load:
_HUNG1995_DATASET_LOADER.load()

return _HUNG1995_DATASET_LOADER
Loading

0 comments on commit deda9ea

Please sign in to comment.