Tuesday, January 3rd, 2012...8:13 pm

A Color Change Charm for Ron Weasley

Jump to Comments

Ron Weasley’s twin brothers Fred and George convinced him that the following poem was a Color Change Charm:

“Sunshine, daisies,
butter mellow,
turn this stupid,
fat rat yellow.”

The incantation of the poem was supposed to turn Ron’s rat Scabbers yellow. All Ron got was teasing and snickering from his brothers! If linear algebra were taught in Charms Class at Hogwarts and applied to Scabbers, how could Ron turn him yellow?

The color of each pixel in an image is determined by a vector (r, g, b). With paint, yellow is a primary color. With RGB, equal amounts of red and green make yellow. Therefore, we will use the following linear transformation on each pixel in Scabbers’ image:

  left(  begin{array}{ccc}  1/3 & 1/3 & 1/3 \  1/3 & 1/3 & 1/3 \  0   & 0   & 0  end{array}  right)  left(  begin{array}{c}  r \  g \  b \  end{array}  right)  =  left(  begin{array}{c}  (r + g + b)/3 \  (r + g + b)/3 \  0  end{array}  right).

This transformation produces the following change:

The white background turned yellow which can be a bit displeasing. It’s almost as if we are wearing yellow-tined glasses.

Note, with this linear transformation a white pixel (255,255,255) becomes (255,255,0), which is full yellow. Let’s make such a pixel black. To do this, we want 255 to become 0 and take 0 to 255. That is, we have the points (0,255) (255,0), which becomes the line:

y = –x+255

This can be done via matrices where we take

N = –Y + 255(1),

where N is the new image, Y is the yellow Scabbers and 1 is the matrix of all ones. This produces the following image:

With some matrix vector multiplication, Ron could have turned Scabbers yellow and snickered at his brothers! While linear algebra isn’t quite the same as a wand from Ollivander’s Wand Shop, it does lead to some magic, at least in a Muggle-ish way.

Leave a Reply