Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation between the color and the spectrum #22

Open
JackW109 opened this issue May 6, 2023 · 2 comments
Open

Relation between the color and the spectrum #22

JackW109 opened this issue May 6, 2023 · 2 comments
Assignees
Labels

Comments

@JackW109
Copy link

JackW109 commented May 6, 2023

Hi-

I am wondering what the function might be relating the spectrum and color for any given color in the "colors" data set?

for example: Van Gaugh's Self Portrait contains the color #64c896, and the spectrum #47b853. And, imageid 429982 contains the color #64967d, and the spectrum #47b853 also. What equation accounts for these "nearest fit" spectrum colors? thanks.

@jeffsteward jeffsteward self-assigned this May 8, 2023
@jeffsteward
Copy link
Contributor

The spectrum in our API is part of the museum's design system. Each day of the year has an assigned color (aka color of the day). (Check it out the spectrum on the HAM Explorer demo website.) We map each color in the "colors" data set to our spectrum in case we want to find objects that contain the color of the day. It's mostly there for fun.

Every image in the API goes through color analysis and binning. The colors array in the root of the object record is there for convenience. It's the same as the colors array found in the first image of the object record.

This is the function used for "nearest fit". (See it in context.)

function _find_closest_spectrum($r, $g, $b){
	$differencearray = array();

	foreach ($this->spectrum as $h => $info) {
		$value = $this->_hex_to_rgb($h);

		$difference = sqrt(pow($r-$value[0],2) + pow($g-$value[1],2) + pow($b-$value[2],2));
		array_push($differencearray, $difference);
	}

	$smallest = min($differencearray);
	$key = array_search($smallest, $differencearray);

	$k = array_keys($this->spectrum);
	return $k[$key];
}

This comes from the code for our color service.

@JackW109
Copy link
Author

Thank you very much!
very clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants