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

Un-mix (or remove) a color? #10

Open
drawtheliner opened this issue Nov 17, 2022 · 2 comments
Open

Un-mix (or remove) a color? #10

drawtheliner opened this issue Nov 17, 2022 · 2 comments

Comments

@drawtheliner
Copy link

Although not possible in real life, can I simulate removing one color from another using mixbox?

For example, since blue and yellow make green, removing yellow from green should make blue.

I tried using a negative mixing ratio and that didn't seem to work.
I also tried inverting the color to be removed first (so a color like (0,5,255) becomes (255,250,0)), but I'm not sure if it worked.

@knokelmaat
Copy link

Mixing is just a linear operation in the latent space (once RGB is converted to latent representation). So inverting that operation is very straightforward (python):

#!/usr/bin/python

import mixbox
import tkinter

color1_rgb = (167, 41, 32)
color1_latent = mixbox.rgb_to_latent(color1_rgb)
color2_rgb = (0, 181, 26)
color2_latent = mixbox.rgb_to_latent(color2_rgb)

# Mix 0.2 of color1 with 0.8 of color2
color_mix_latent = [0.2 * color1_latent[i] + 0.8 * color2_latent[i] for i in range(mixbox.LATENT_SIZE)]
color_mix_rgb = mixbox.latent_to_rgb(color_mix_latent)

# Convert mixed color back from RGB -> LATENT
#color_mix_latent = mixbox.rgb_to_latent(color_mix_rgb)

# Unmix
color1_guess_latent = [(color_mix_latent[i] - 0.8 * color2_latent[i]) / 0.2 for i in range(mixbox.LATENT_SIZE)]
color1_guess_rgb = mixbox.latent_to_rgb(color1_guess_latent)

# Print results
print("0.2 of", color1_rgb, "and 0.8 of", color2_rgb, "->", color_mix_rgb)
print("take 0.8 of ", color2_rgb, "out of", color_mix_rgb, "->", color1_guess_rgb)

# Show results graphically
root = tkinter.Tk()

e = tkinter.Label(root, width=20,height=2,text='#%02x%02x%02x' % color1_rgb, background='#%02x%02x%02x' % color1_rgb)
e.grid(row=0)
e = tkinter.Label(root, width=20,height=2,text='#%02x%02x%02x' % color2_rgb, background='#%02x%02x%02x' % color2_rgb)
e.grid(row=1)
e = tkinter.Label(root, width=20,height=2,text='#%02x%02x%02x' % color_mix_rgb, background='#%02x%02x%02x' % color_mix_rgb)
e.grid(row=2)
e = tkinter.Label(root, width=20,height=2,text='#%02x%02x%02x' % color1_guess_rgb, background='#%02x%02x%02x' % color1_guess_rgb)
e.grid(row=3)

root.mainloop()

Running this results in a color1_guess_rgb that is identical to the original color1.

However, if you look closely, you can see that I commented out the conversion from LATENT -> RGB -> LATENT for the mixed color. If I leave that line in, you no longer get a similar result. This is because seemingly LATENT -> RGB -> LATENT does not give similar results in latent space. But I suppose this is an altogether different issue that can be discussed (and is probably linked to #11).

@drawtheliner
Copy link
Author

Thank you for that!

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

No branches or pull requests

2 participants