I have written a program in VB.NET to generate just one face of a YCbCr colour space cube. I want the final image to look similar to the CbCr plane at constant luma on Wikipedia (where Y=1).
Ultimately, I want to create images of all 6 faces of the cube, so that I can make an animated 3D cube in Photoshop (I already know how to create the cube in Photoshop once I have images of its faces). The finished cube will look similar to the YUV cube on the softpixel website.
Below is the output of my program and the code so far. I had no trouble generating the faces of an RGB colour space cube, but the YCbCr cube is proving problematic. I have applied a YCbCr conversion formula to each pixel in the face of an RGB cube, but the centre of the front face should be white and the centre of the opposite face should be black. Can someone please tell me what code I am missing?
Public Class Form2
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
PictureBox1.Width = 255
PictureBox1.Height = 255
'create new bitmap
Dim newbmp As Bitmap = New Bitmap(255, 255)
'Generate the new image
Dim x As Integer
Dim y As Integer
For y = 0 To 254
For x = 0 To 254
Dim yval As Integer
Dim cb As Integer
Dim cr As Integer
'Convert to YCbCr using these formulas
'0+(0.299*RED)+(0.587*GREEN)+(0.114*BLUE)
'128-(0.168736*RED)-(0.331264*GREEN)+(0.5*BLUE)
'128+(0.5*RED)-(0.418688*GREEN)-(0.081312*BLUE)
yval = Math.Floor(0 + (0.299 * x) + (0.587 * y) + (0.114 * 255))
cb = Math.Floor(128 - (0.168736 * x) - (0.331264 * y) + (0.5 * 255))
cr = Math.Floor(128 + (0.5 * x) - (0.418688 * y) - (0.081312 * 255))
newbmp.SetPixel(x, y, Color.FromArgb(yval, cb, cr))
Next x
Next y
'load image into picturebox
PictureBox1.Image = newbmp
End Sub
End Class