Find if RGB value is complementary or analogous to another RGB value in Python?
I have two RGB numbers. I am trying to find if the colors "match" (in the sense that clothing colors match or go together).
I am attempting to make a function that checks if color1 and color2 are analogous to each other (or close enough/within range).
I also need to make a function that checks if color1 and color2 are complementary to eachother.
My current code is as follows:
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
from colorharmonies import Color, complementaryColor, triadicColor, splitComplementaryColor, tetradicColor, analogousColor, monochromaticColor
from math import sqrt
def isComp(color1, color2):
color1 = Color(color1, "", "")
comp = complementaryColor(color1)
diff = colDiff(comp, color2)
#print(diff)
return diff <= 20.0
def isAnalg(color1, color2):
color1 = Color(color1, "", "")
analg = analogousColor(color1)
diff1 = colDiff(analg[0], color2)
diff2 = colDiff(analg[0], color2)
#print(diff)
return diff1 <= 70.0 or diff2 <= 70.0
def colDiff(c1, c2):
# Red Color
color1_rgb = sRGBColor(float(c1[0]), float(c1[1]), float(c1[2]))
# Blue Color
color2_rgb = sRGBColor(float(c2[0]), float(c2[1]), float(c2[2]))
# Convert from RGB to Lab Color Space
color1_lab = convert_color(color1_rgb, LabColor)
# Convert from RGB to Lab Color Space
color2_lab = convert_color(color2_rgb, LabColor)
# Find the color difference
return delta_e_cie2000(color1_lab, color2_lab)
However, this code does not work. Could anyone give me a suggestion or library that I could use? Or some code? Thank you.
python-3.x colors
add a comment |
I have two RGB numbers. I am trying to find if the colors "match" (in the sense that clothing colors match or go together).
I am attempting to make a function that checks if color1 and color2 are analogous to each other (or close enough/within range).
I also need to make a function that checks if color1 and color2 are complementary to eachother.
My current code is as follows:
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
from colorharmonies import Color, complementaryColor, triadicColor, splitComplementaryColor, tetradicColor, analogousColor, monochromaticColor
from math import sqrt
def isComp(color1, color2):
color1 = Color(color1, "", "")
comp = complementaryColor(color1)
diff = colDiff(comp, color2)
#print(diff)
return diff <= 20.0
def isAnalg(color1, color2):
color1 = Color(color1, "", "")
analg = analogousColor(color1)
diff1 = colDiff(analg[0], color2)
diff2 = colDiff(analg[0], color2)
#print(diff)
return diff1 <= 70.0 or diff2 <= 70.0
def colDiff(c1, c2):
# Red Color
color1_rgb = sRGBColor(float(c1[0]), float(c1[1]), float(c1[2]))
# Blue Color
color2_rgb = sRGBColor(float(c2[0]), float(c2[1]), float(c2[2]))
# Convert from RGB to Lab Color Space
color1_lab = convert_color(color1_rgb, LabColor)
# Convert from RGB to Lab Color Space
color2_lab = convert_color(color2_rgb, LabColor)
# Find the color difference
return delta_e_cie2000(color1_lab, color2_lab)
However, this code does not work. Could anyone give me a suggestion or library that I could use? Or some code? Thank you.
python-3.x colors
add a comment |
I have two RGB numbers. I am trying to find if the colors "match" (in the sense that clothing colors match or go together).
I am attempting to make a function that checks if color1 and color2 are analogous to each other (or close enough/within range).
I also need to make a function that checks if color1 and color2 are complementary to eachother.
My current code is as follows:
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
from colorharmonies import Color, complementaryColor, triadicColor, splitComplementaryColor, tetradicColor, analogousColor, monochromaticColor
from math import sqrt
def isComp(color1, color2):
color1 = Color(color1, "", "")
comp = complementaryColor(color1)
diff = colDiff(comp, color2)
#print(diff)
return diff <= 20.0
def isAnalg(color1, color2):
color1 = Color(color1, "", "")
analg = analogousColor(color1)
diff1 = colDiff(analg[0], color2)
diff2 = colDiff(analg[0], color2)
#print(diff)
return diff1 <= 70.0 or diff2 <= 70.0
def colDiff(c1, c2):
# Red Color
color1_rgb = sRGBColor(float(c1[0]), float(c1[1]), float(c1[2]))
# Blue Color
color2_rgb = sRGBColor(float(c2[0]), float(c2[1]), float(c2[2]))
# Convert from RGB to Lab Color Space
color1_lab = convert_color(color1_rgb, LabColor)
# Convert from RGB to Lab Color Space
color2_lab = convert_color(color2_rgb, LabColor)
# Find the color difference
return delta_e_cie2000(color1_lab, color2_lab)
However, this code does not work. Could anyone give me a suggestion or library that I could use? Or some code? Thank you.
python-3.x colors
I have two RGB numbers. I am trying to find if the colors "match" (in the sense that clothing colors match or go together).
I am attempting to make a function that checks if color1 and color2 are analogous to each other (or close enough/within range).
I also need to make a function that checks if color1 and color2 are complementary to eachother.
My current code is as follows:
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
from colorharmonies import Color, complementaryColor, triadicColor, splitComplementaryColor, tetradicColor, analogousColor, monochromaticColor
from math import sqrt
def isComp(color1, color2):
color1 = Color(color1, "", "")
comp = complementaryColor(color1)
diff = colDiff(comp, color2)
#print(diff)
return diff <= 20.0
def isAnalg(color1, color2):
color1 = Color(color1, "", "")
analg = analogousColor(color1)
diff1 = colDiff(analg[0], color2)
diff2 = colDiff(analg[0], color2)
#print(diff)
return diff1 <= 70.0 or diff2 <= 70.0
def colDiff(c1, c2):
# Red Color
color1_rgb = sRGBColor(float(c1[0]), float(c1[1]), float(c1[2]))
# Blue Color
color2_rgb = sRGBColor(float(c2[0]), float(c2[1]), float(c2[2]))
# Convert from RGB to Lab Color Space
color1_lab = convert_color(color1_rgb, LabColor)
# Convert from RGB to Lab Color Space
color2_lab = convert_color(color2_rgb, LabColor)
# Find the color difference
return delta_e_cie2000(color1_lab, color2_lab)
However, this code does not work. Could anyone give me a suggestion or library that I could use? Or some code? Thank you.
python-3.x colors
python-3.x colors
asked Jan 19 at 16:18
GabeGabe
205
205
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54269032%2ffind-if-rgb-value-is-complementary-or-analogous-to-another-rgb-value-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54269032%2ffind-if-rgb-value-is-complementary-or-analogous-to-another-rgb-value-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown