March 12th, 2010

Go to page: 1 2 3 4 5 Next

Home-brewed “color spacing”


Note: apparently, not all the code below displays correctly via RSS.

Here’s a home-brewed way to get some of those expensive looking “color aware” effects.

In addition to the original hue/saturation/brightness components, I create six new variables each for hue, saturation, and value (brightness), plus six “weight” values, each corresponding with one of the six colors of a preschooler’s rainbow, ROYGBV (red, orange, yellow, green, blue — fuck “indigo”, but if you wanted me to take it seriously as a color, you should have taught it to me sooner — and violet, even though we called it “purple”):

double h, hueR, hueO, hueY, hueG, hueB, hueV;
double s, satR, satO, satY, satG, satB, satV;
double v, valR, valO, valY, valG, valB, valV;
double wR, wO, wY, wG, wB, wV;

Then at each pixel, you set up the “weight” values depending on what it’s closest to:

wR = wO = wY = wG = wB = wV = 0.0;
if (h >= 0 && h < = 21 ){wO = h /21.0; wR = 1.0 - wO;}
if (h > 21 && h < = 42 ){wY = (h - 21.0 )/21.0; wO = 1.0 - wY;}
if (h > 42 && h < = 85 ){wG = (h - 42.0 )/43.0; wY = 1.0 - wG;}
if (h > 85 && h < = 170){wB = (h - 85.0 )/85.0; wG = 1.0 - wB;}
if (h > 170 && h < = 212){wV = (h - 170.0)/42.0; wB = 1.0 - wV;}
if (h > 212 && h < = 255){wR = (h - 212.0)/43.0; wV = 1.0 - wR;}

Notice that it’s not just selecting one color and going with that; if it’s halfway between red and orange, the red weight would be 0.5, the orange weight would be 0.5, and all the other weights would be zero. After this point in the code, you’re now free to experiment with each value separately. For example, if you want to kill all saturation for the yellow areas, and just turn them grayscale, you would code it this way:

satY = 0;

Similarly, if I want to pump the heck out of the blue areas, I put a line like this:

satB *= 2;

(That’s C++ for “multiply by two”.)

Additionally, I “limit” the red saturation, so that it stays the same up to a point, but doesn’t go any higher; so that skin still looks the same, but bright red ribbons are muted:

if (satR > 96.0) satR = 96;

This example only plays with saturation. I could also mess around with brightness, contrast, etc. in the same way. After this designated “fun sandbox” section is the code that puts together the final values, using the “weight” values:

h = wR*hueR + wO*hueO + wY*hueY + wG*hueG + wB*hueB + wV*hueV;
s = wR*satR + wO*satO + wY*satY + wG*satG + wB*satB + wV*satV;
v = wR*valR + wO*valO + wY*valY + wG*valG + wB*valB + wV*valV;
setpixel(x, y, h, s, v);

I’m not sure exactly how this stacks up against the “color spacing” technology the big companies charge lots of money for, since like I said, it’s based on a Crayola-level color awareness. That considered though, it’s free in both senses of the word… free as in no expensive software to pay for, and free as in freedom to experiment on any of those 18 values with all kinds of math and logic before reducing them back to the original three components.

Much thanks to Darel Rex Finley, since I’m now using his HSP Color Model code to switch the images back and forth between RGB mode and HSP mode. “P” in this case is “perceived brightness”, and more psychovisually accurate than standard “V” or “L” values, but serves the same purpose. Check out his clear and well-illustrated HSP page for an explanation of the difference.

Is this thing on?


So, like, I’m supposed to be posting to this thing, right? Is that how it works?

The experts would probably suggest that I break my blogger’s block by shooting for ephemeral, disposable, and monk-like, and not trying to make each post a timeless work of art. I’d still like to have an amusing picture for every post — because reading is more enjoyable when there’s a pretty picture to lure you in — but that’s seriously a pain in the ass to do consistently. I could outline the extra steps here, but then I’d be subjecting you to the same torture.

So, after writing the previous paragraph, I put my jacket on, got in my car, and drove 1.8 miles out and back in icy, windy, finger-shattering weather, to pick up a latte. See? This is exactly what I’m talkin’ about, peoples. I can’t even write a danged blog post without interrupting it for something “important” — like a latte.

I suppose when you’re spending more and more time doing something that falls outside your previously defined identity, there’ll be some mental re-integration work to do. Right now, it’s about all the free hours eaten up by improv rehearsals. It’s all positive, but it does force me to ask questions like, “will I actually accomplish the other stuff I started?”

And the answer to that is, yes, that’s actually part of the reason I got involved in the first place.

Epilogue: Republicans


On January 27th, I posted an Open Letter to Republicans, and I think the question still holds up.

Granted, the site only gets a dozen hits or day, mostly from people looking for images to steal — but I’m sure that post was seen by at least one or two republicans. I’m sure you had ample opportunity to give me at least one rational reason to take you seriously. I told you I was undecided. I told you I’m not a member of any political party. I told you I was truly open minded, and truly listening.

I’m sure if you never saw my post, you at least came across one or two other non-republicans with a similar question or plea, essentially, “please give me some kind of counterpoint to the ideals I’m being presented with from the democratic side, so that I can weigh it and think about it objectively”. I’m sure that with all the people in the world, this question has come up somewhere, and at least one of you out there somewhere could have answered it in some form.

Instead, all we got from you was a paper bag that you had taken a shit in and set to fire, saying, “here, you stupid liberal”.

Point made, if all you ever had in the first place was shit. “Obama hates whites. No, wait, he hates God. He hates the military and America and our freedom, and wants us to lose. He’s a terrorist. Er, sorry, a socialist. A Muslim? An Arab? My bad, he’s a baby killer. He’s launching a war on coal! Wait, what are we going with this week? Whatever he is, I ain’t paying taxes to him and he represents the downfall of this great country (in which I hate the majority of citizens, especially if they’re different than me, and am out riding a tank to defend them and ought to be appreciated for it, only I wouldn’t articulate it that well because I failed third-grade English)!” Small wonder we can barely remember your candidate’s name, as you haven’t actually found anything to say about him.

I understand the basic premise of conservatism: small government, low taxes. I’ve been through my Ayn Rand phase, and would be respectful of that position, if that’s what your position actually was. Unfortunately, you spew on and on about “pork” and “earmarks” while pouring billions into blowing up an area of the middle east that never threatened us. Unfortunately you don’t see the hypocrisy of worrying about welfare recipients collecting a few hundred bucks for supposedly being lazy and doing nothing, while CEOs, upper management, and shareholders collect millions for simply having a high and often un-earned position, or being lucky enough to have started the game with more chips on the table. (If you think most of those guys are “creating value”, you have a pretty rosy view of corporate America.) Then you accept bribes from those same big-wigs, to stifle technologies that would threaten jobs in obsolete 20th century industries… you mean a coal tycoon might have to take an entry level position in wind or solar? Gee, what was that you were saying earlier about “bootstraps”?

Look, republicans, I could have been a great mouthpiece for you. Many of my independent friends could have helped you too. See, ideas matter. Words matter. If you have anything worth saying, I encourage you to let me know. Tonight we saw that a positive campaign can win against a negative campaign. That you don’t have to be dirty. That you don’t have to dumb yourself down. That you don’t have to rouse people up to “boo” your opponent. That you can win by inspiring real hope in people, and focusing on what’s possible, not on what we should be “afraid” of.

I do, however, appreciate the flaming paper bag of shit you’ve provided us with over the past several months, in the form of YouTube comments, FOX news reports, and the Neanderthal-like, half-grunting, half-chanting sound you make at rallies. It’s a glowing reminder that it doesn’t always pay to be an asshole.

1111111


This probably means something…

…not sure what, though. Anyways, happy ghostie day, peeps!

“Add child back to adjusted parent”


The entire weekend — apart from a couple of alarm-free mornings and one two-hour VIP rehearsal — was spent continuing work on a set of hand-coded image processing algos, to help make reality look more arty-cartoon-surreal for the just-barely-started film project.

What that means is writing stuff like this:

Translating it into stuff like this:

And compiling and running it to make effects like this:

Which you can see animated (in crappy quality) here:

This is not the “complete” effect, just the stage of development that it’s at.

The pseudocode in the top picture was written in a restaurant, and it wound up being one of those rare occasions where the waitress actually asked what I was doing. I did my best to explain it in human terms without dumbing it down to the point of condescension.

Just below that is the code resulting from that handwritten idea, in this case a combined blur/sharpen filter, which happens to be my first-ever recursive function. What that means is, when the function “happens”, it spawns a copy of itself, which also spawns a copy of itself, and so on. As you might guess, this would lead to some kind of crash, if it didn’t have some built-in way of eventually stopping itself — which, I suppose, is part of the thrill of writing it. Honest to golly, though, I went this route because it was the best solution for a problem, not for the sake of flirting with danger.

Most of what you’re seeing are other effects: a median filter, an auto-outlining effect, and a partial desaturation.

I’m still here, still active, etc…


I didn’t mean to leave the Rick Wright obituary at the top of my blog for week after week after week, as if it Wright’s passing had eternally crushed my spirit. I’ve literally been so busy lately that it’s hard to find time to adequately cover the activities I have going on.

And that’s a good thing.

I do promise to get the long versions of my updates up here sometime soon. In the meantime, if you want the short versions.. I don’t have enough friends on Twitter (hint, hint). If you have an account, I’d love for you to head over there and start “following” me, and I’ll certainly “follow” you back.

More soon…

Go to page: 1 2 3 4 5 Next

Imhotep theme designed by Chris Lin (and then bastardized by the webmaster). Proudly powered by Wordpress.
XHTML | CSS | RSS | Comments RSS