RGB converted to YUV does use those formulae. But each channel ends up being grayscale and not colored. They only show as a colored image togther when displayed as if RGB. That is combine the individual grayscale channels into a 3-channel image and display as if RGB. But each channel Y,U,V are each grayscale. So I don't see anything in that reference that tells me how they colored the U and V channels by themselves.
There is some code on how the images were generated if one clicks on the picture at
http://en.wikipedia.org/wiki/File:Barn-yuv.png, and I think I see what they have done. For each of U, V, they set one channel to 0, one to U and one to the negate of U (255-U). Then combine those 3 channels into a color (RGB) image. Similarly for V but a different order. However, this is still artificially coloring the U and V channels.
Nevetheless try the following:
barn.png
# first line -- convert to and separate Y,U,V
# second line -- copy Y
# third line -- copy U and make all black
# fourth line -- copy U and invert (negate)
# fifth line -- copy U
# sixth line -- combine lines 3,4,5 as RGB colored version of U
# seventh line -- copy V
# eighth line -- copy V and negate (invert)
# ninth line -- copy V and make all black
# tenth line combine lines 7,8,9 as RGB colored version of V
# eleventh line -- delete unneeded copies and append the Y, colored U and colored V into output image
convert barn.png -colorspace YUV -sampling-factor 4:2:2 -separate \
\( -clone 0 \) \
\( -clone 1 -fill black -colorize 100% \) \
\( -clone 1 -negate \) \
\( -clone 1 \) \
\( -clone 4 -clone 5 -clone 6 -combine\) \
\( -clone 2 \) \
\( -clone 2 -negate \) \
\( -clone 2 -fill black -colorize 100% \) \
\( -clone 8 -clone 9 -clone 10 -combine \) \
-delete 0-2,4-6,8-10 -append \
barn_yuv_append.png
The key lines of the code in the reference are:
convert to YUV, then make the colored versions of U and V and keep Y as grayscale (but 3 channels)
$yuv_img->setPixel($x, $height+$y, cached_allocate($yuv_img, $Y, $Y, $Y));
$yuv_img->setPixel($x, 2*$height+$y, cached_allocate($yuv_img, 0, 255-$U, $U));
$yuv_img->setPixel($x, 3*$height+$y, cached_allocate($yuv_img, $V, 255-$V, 0));