1. 2010
    Jun
    13

    CMYK to RGB conversion

    It certainly took long enough, but after an hour or so of hunting I finally tracked down the formula that the ImageMagick color converter uses to convert CMYK colors into RGB. I rewrote it a little to make the expression more illuminating:

    $$r = Q_R (1 - c / Q_R)(1 - k / Q_R)$$
    $$g = Q_R (1 - m / Q_R)(1 - k / Q_R)$$
    $$b = Q_R (1 - y / Q_R)(1 - k / Q_R)$$

    for a CMYK color point \((c,m,y,k)\) and RGB color point \((r,g,b)\). The tricky part to locate was the constant \(Q_R\), and a related constant \(Q_S\), which ImageMagick calls QuantumRange and QuantumScale respectively.

    • \(Q_R\) is the range that each of the color values can take on, so if each of your channels (red, green, blue, cyan, magenta, yellow, black) is given by a number from 0–255, for example, \(Q_R\) would be 255.
    • \(Q_S\) is actually just the reciprocal of \(Q_R\). I suspect they give it a different name only because floating-point division is pretty inefficient so it saves some CPU cycles to precompute \(1/Q_R\).

    If anyone wants to track it down themselves, the algorithm is in the ConvertCMYKToRGB function in the ImageMagick source code (line 1327 of colorspace …

  2. 2010
    Jun
    11

    Decapitation: Energy or momentum?

    http://scienceblogs.com/dotphysics/2010/06/collisions_kinetic_energy_or_m.php

    Took the words right out of my mouth. Or right off my keyboard. Whatever. I’m just happy to see other people are considering the same questions.

    But I’ve got a couple of things to add. First of all, kinetic energy can be easily related to momentum using the formula

    $$K = \frac{p^2}{2m}$$

    which tells you directly that an object with the same energy but larger mass will have a larger momentum.

    Also, the big question: is it energy or momentum that gives a collision its decapitating power? My thought is that it actually depends on force. Think about this from the point of view of a particle in the neck. This particle doesn’t “know” (as if a particle could “know” anything) how big the sheet of glass hitting it is; it doesn’t “know” how much energy or momentum the glass has. The reason is that energy and momentum are what I’m going to call global properties, basically meaning that the total amount of them possessed by some object comes from contributions from all different pieces of the object. To measure a global property of the …

  3. 2010
    Jun
    10

    Firework Man

    More Mythbusters! Yayyy!

    Just kidding, I am not that incessantly perky. But I did have an interesting thought while watching last week’s episode of Mythbusters. Kari, Tory, and Grant were testing the myth that a man in Germany launched himself 150 feet high using 400 firecrackers and splashed down safely in a lake. First of all, how dumb is this guy? Darwin Award anyone? (I guess he’d technically be ineligible since in the myth, he survived unharmed, but it was certainly a noble effort)

    Anyway, here’s my physics thought of the week for last week: \(v = \sqrt{2gh}\). That’s the formula for the vertical velocity you need to reach a certain height as a ballistic projectile. To get 150 feet of altitude requires \(\unit{47}{\mileperhour}\), and that’s if you launch straight up. Coming off an angled ramp, as they did in the show, you’d have to be going even faster. Of course, the guy in the myth isn’t quite a ballistic projectile; he gets an extended boost from the rockets. But still, \(\unit{150}{\foot}\) of altitude is pushing it, so I would have been inclined (pun? intended? nah) to dismiss this …

  4. 2010
    May
    23

    Waterslide Wipeout

    Like everyone else, I feel a need to analyze the giant water slide in the latest Mythbusters episode. But honestly, there isn’t much left to say. The original video has been around for a while and everybody else who does this kind of analysis has already had the chance to do it. Example 1; example 2 (okay, so I’m only linking to one blog, but there must be more).

    I guess I might as well do the obvious calculation, but I’ll use the Mythbusters’ parameters instead of those from the original video (which are unknown). The slide starts with a downward ramp \(\unit{165}{\foot}\) long at a \(\unit{24}{\degree}\) slope, which then curves upward to a \(\unit{30}{\degree}\) launch ramp that terminates \(\unit{12}{\foot}\) above the surface of the lake. They didn’t say how long the launch ramp is, but I can work without that information. I’ll be trying to calculate two quantities mentioned on the show: how far each Mythbuster flies from the end of the ramp, and his maximum speed.

    (here’s a full-size version)

    There are two parts to this problem:

    1. The slide
    2. The flight

    The first part …

  5. 2010
    May
    17

    Google's apology

    The news of Google’s Street View cars collecting WiFi data has been echoed around the internet for a while now. Now, obviously this is a Bad Thing that they shouldn’t have been doing, and there should have been internal checks in place to make sure it didn’t happen. Fine, I agree. But the fact that it did happen doesn’t make them evil, as a lot of people seem to be saying. According to the official blog entry at least (which I don’t have any particular reason to doubt), it was a mistake. Mistakes happen, and a large organization like Google is going to have a correspondingly large number of them.

    Now, think about it from the perspective of the Google people. Once they found out this happened, they couldn’t go back in time and prevent it. The data had already been collected, the news had already been released. Under the circumstances, deleting the data and shutting down the WiFi scanning was pretty much all they could do. Rereading the blog post, it occurs to me that this is pretty much the kind of reaction I’d want to see from a company in their …

  6. 2010
    May
    15

    The power of collaborative answering

    StackOverflow, and more generally the idea of a collaborative, community-moderated Q&A site, is a great invention, although I don’t quite share Jeff Atwood’s level of enthusiasm for it (or at least not his maniacal obsession with overthrowing the phpBB empire and conquering the universe of online information exchange). I mean, I don’t think it has that much of an advantage over the traditional web forum, especially given that since answers are editable and ordered by vote count (which changes frequently), it’s hard to hold and follow a discussion when just a simple “this is the answer” post doesn’t suffice.

    But every once in a while, the StackOverflow model really gets a chance to shine. Take a look at this question about improving a Python function’s coding style. The top answer is a model of beautiful Python coding with iterators (well, in that peculiar sense of “beautiful” that only an experienced Python programmer can appreciate), but it didn’t start out that way. There were three of us who answered almost immediately, each making one or two little improvements to the code posted by the original questioner, and then over the next 15 minutes …

  7. 2010
    May
    13

    KDE environment variables

    Let's say I want to set an environment variable so that its value will be available to all KDE applications. It's surprisingly hard to figure out how to do this — the usual Google-fu techniques come up with a lot of noise. So I wound up digging through the source to startkde (prompted by TechBase's description of the startup sequence) and figured out how to do it: any scripts with filenames matching $KDEHOME/env/*.sh will be run on startup, and changes they make to the environment are propagated to all KDE applications. Similarly to run a script on shutdown, name it something that matches $KDEHOME/shutdown/*.sh.

    To find the full list of directories that KDE searches for shell scripts to run on startup, here's the command, pulled right out of startkde (well, in so many words):

    kde4-config --path lib | tr : '\n' | sed -n -e 's,/lib[^/]*/,/env/,p'