HSI terdiri dari bilangan Hue, Saturation dan Intensity, untuk memasukkan bilangan
HSI ke function/method HSI_RGB diatas, data dipisahkan oleh tanda koma (,), jadi
contoh pengiriman parameter ke function/method HSI_RGB diatas adalah 251,
0.756, 0.426. Output dari function ini akan berupa data RGB bertipe string, contoh :
67, 27, 231.
II.9 TRANSFORMASI RGB KE HCL
Untuk mentransformasi dari RGB ke HCL. Diasumsikan koordinat-koordinat R, G, B
[0,1] adalah berurutan merah, hijau, biru dalam ruang warna RGB, dengan max
adalah nilai maksimum dari nilai red, green, blue, dan min adalah nilai minimum dari
nilai red, green, blue. Untuk memperoleh luminance untuk ruang warna HCL,
menggunakan rumus seperti berikut [Madenda and Missaoui, 2005] :
. , , 1 . ,,
2
dimana . adalah parameter yang memungkinkan untuk pengaturan terhadap
pengaruh perubahan intensitas, α=0 jika Max(R,G,B)=0, dan jika tidak ,, .
,,
Sedang parameter Y0 adalah nilai stimulasi untuk referensi warnah putih dimana Y0
= 100 untuk standar iluminasi CIE D65. Parameter γ (1 ≤ γ ≤ 31) adalah faktor
koreksi terhadap kondisi pencahayaan manusia.
| | | | | |
Untuk Hue adalah, 3
arctan
0 2
3
0 0
60
0 0 180
0 0 4
3
120
2
0 0 3 180
50
Misalnya ingin ditransformasikan RGB(65, 27, 234) ke dalam bentuk HCL, maka
langkahnya adalah sebagai berikut :
Setiap nilai RGB(65, 67, 234) diubah dalam jangkauan [0,1] dengan membagi setiap
nilai dengan 255 :
menjadi , , = 0.255, 0.106, 0.918
RGB(0.255, 0.106, 0.918) ini yang akan ditransformasikan ke bentuk HCL.
Max(R, G, B) = nilai B (blue) = 0.918, Min (R, G, B) =nilai G (green) = 0.106.
α= ,, . = 0.001154684
,, .
parameter γ (Gamma) kita ambil = 30.
Q= .= . = . = 1.035
L = . , , . , , . . . . 0.477
C = | | | | | | . | . . | | . . | | . . | 0.56
H = arctan arctan . . arctan 5.45 79.6
. .
Karena, R – G = 0.255 – 0.106 = 0.149 > 0, dan
G – B = 0.106 – 0.918 = -0.812 < 0, maka
H = 79.6 106.13
sehingga nilai RGB(65, 27, 234) ditransformasikan menjadi HCL(-106.130, 0.56,
0.477) dengan jangkauan RGB [0,1].
Berdasarkan langkah-langkah transformasi diatas, maka untuk
mengimplementasikan ke bahasa pemrograman adalah sebagai berikut :
51
II.10.A VISUAL BASIC 6
0 Private Function RGB_HCL(RGB As String, Gamma As Double) As String
1 Dim strData() As String
2 Const PI As Double = 3.14159265358979
3
4 strData = Split(RGB, ",")
5 If UBound(strData) >= 2 Then
6 Dim R As Double, G As Double, B As Double
7 Dim alpha As Double, max As Double, min As Double
8 Dim Q As Double, L As Double, C As Double, H As Double
9
10 R = CDbl(strData(0)) / 255
11 G = CDbl(strData(1)) / 255
12 B = CDbl(strData(2)) / 255
13 max = R
14 If max < G Then max = G
15 If max < B Then max = B
16 min = R
17 If min > G Then min = G
18 If min > B Then min = B
19
20 alpha = min / (max * Gamma)
21 Q = Exp(alpha)
22 L = ((Q * max) + ((Q - 1) * min)) / 2
23 C = (Q * (Abs(R - G) + Abs(G - B) + Abs(B - R))) / 3
24
25 H = Atn((G - B) / (R - G)) * (180 / PI)
26 If R = G And R = B Then
27 H = -1
28 ElseIf G = B And G < R Then
29 H = 0
30 ElseIf (R - G >= 0) And (G - B) >= 0 Then
31 H = (2 * H) / 3
32 ElseIf R = G And R > B Then
33 H = 60
34 ElseIf (R - G < 0) And (G - B >= 0) Then
35 H = 180 + ((4 * H) / 3)
36 ElseIf (R - G >= 0) And (G - B < 0) Then
37 H = (4 * H) / 3
38 ElseIf R = G And R < B Then
39 H = -120
40 ElseIf (R - G < 0) And (G - B < 0) Then
41 H = ((2 * H) / 3) - 180
42 End If
43 End If
44
45 RGB_HCL = Format$(H, "0.000") + "," + Format$(C, "0.000") + "," + Format$(L, "0.000")
46 End Function
52
II.10.A VISUAL BASIC.NET
0 Private Function RGB_HCL(ByVal RGB As String, ByVal Gamma As Double) As String
1 Dim strData() As String
2 Dim Q As Double, L As Double, C As Double, H As Double
3 Const PI As Double = 3.14159265358979
4
5 strData = RGB.Split(",")
6 If strData.Length >= 3 Then
7 Dim R As Double, G As Double, B As Double
8 Dim alpha As Double, max As Double, min As Double
9
10 R = Double.Parse(strData(0)) / 255
11 G = Double.Parse(strData(1)) / 255
12 B = Double.Parse(strData(2)) / 255
13 max = R
14 If max < G Then max = G
15 If max < B Then max = B
16 min = R
17 If min > G Then min = G
18 If min > B Then min = B
19
20 alpha = min / (max * Gamma)
21 Q = Math.Exp(alpha)
22 L = ((Q * max) + ((Q - 1) * min)) / 2
23 C = (Q * (Math.Abs(R - G) + Math.Abs(G - B) + Math.Abs(B - R))) / 3
24
25 H = Math.Atan((G - B) / (R - G)) * (180 / PI)
26 If R = G And R = B Then
27 H = -1
28 ElseIf G = B And G < R Then
29 H = 0
30 ElseIf (R - G >= 0) And (G - B) >= 0 Then
31 H = (2 * H) / 3
32 ElseIf R = G And R > B Then
33 H = 60
34 ElseIf (R - G < 0) And (G - B >= 0) Then
35 H = 180 + ((4 * H) / 3)
36 ElseIf (R - G >= 0) And (G - B < 0) Then
37 H = (4 * H) / 3
38 ElseIf R = G And R < B Then
39 H = -120
40 ElseIf (R - G < 0) And (G - B < 0) Then
41 H = ((2 * H) / 3) - 180
42 End If
43 End If
44
45 Return H.ToString("0.000") + "," + C.ToString("0.000") + "," + L.ToString("0.000")
46 End Function
53
II.10.A C#
0 private string RGB_HCL(string RGB, double Gamma)
1{
2 string[] strData;
3 double Q, L=0, C=0, H=0;
4 const double PI = 3.14159265358979;
5
6 strData = RGB.Split(',');
7 if (strData.Length >= 3)
8{
9 double R, G, B;
10 double alpha, max, min;
11
12 R = double.Parse(strData[0]) / 255;
13 G = double.Parse(strData[1]) / 255;
14 B = double.Parse(strData[2]) / 255;
15 max = R;
16 if (max < G) max = G;
17 if (max < B) max = B;
18 min = R;
19 if (min > G) min = G;
20 if (min > B) min = B;
21
22 alpha = min / (max * Gamma);
23 Q = Math.Exp(alpha);
24 L = ((Q * max) + ((Q - 1) * min)) / 2;
25 C = (Q * (Math.Abs(R - G) + Math.Abs(G - B) + Math.Abs(B - R))) / 3;
26
27 H = Math.Atan((G - B) / (R - G)) * (180 / PI);
28 if (R == G && R == B)
29 H = -1;
30 else if (G == B && G < R)
31 H = 0;
32 else if ( (R - G >= 0) && (G - B) >= 0)
33 H = (2 * H) / 3;
34 else if ( R == G && R > B)
35 H = 60;
36 else if ( (R - G < 0) && (G - B >= 0))
37 H = 180 + ((4 * H) / 3);
38 else if ( (R - G >= 0) && (G - B < 0))
39 H = (4 * H) / 3;
40 else if (R == G && R < B)
41 H = -120;
42 else if ((R - G < 0) && (G - B < 0))
43 H = ((2 * H) / 3) - 180;
44 }
45
46 return H.ToString("0.000") + "," + C.ToString("0.000") + "," + L.ToString("0.000");
47 }
54
II.10.A JAVA 55
0 private String RGB_HCL(String RGB, double Gamma)
1{
2 String[] strData;
3 double Q, L=0, C=0, H=0;
4 double PI = 3.14159265358979;
5
6 strData = RGB.split(",");
7 if (strData.length >= 2)
8{
9 double R, G, B;
10 double alpha, max, min;
11
12 R = Double.parseDouble(strData[0]) / 255;
13 G = Double.parseDouble(strData[1]) / 255;
14 B = Double.parseDouble(strData[2]) / 255;
15 max = R;
16 if (max < G) max = G;
17 if (max < B) max = B;
18 min = R;
19 if (min > G) min = G;
20 if (min > B) min = B;
21
22 alpha = min / (max * Gamma);
23 Q = Math.exp(alpha);
24 L = ((Q * max) + ((Q - 1) * min)) / 2;
25 C = (Q * (Math.abs(R - G) + Math.abs(G - B) + Math.abs(B - R))) / 3;
26
27 H = Math.atan((G - B) / (R - G)) * (180 / PI);
28 if (R == G && R == B)
29 H = -1;
30 else if (G == B && G < R)
31 H = 0;
32 else if ( (R - G >= 0) && (G - B) >= 0)
33 H = (2 * H) / 3;
34 else if ( R == G && R > B)
35 H = 60;
36 else if ( (R - G < 0) && (G - B >= 0))
37 H = 180 + ((4 * H) / 3);
38 else if ( (R - G >= 0) && (G - B < 0))
39 H = (4 * H) / 3;
40 else if (R == G && R < B)
41 H = -120;
42 else if ((R - G < 0) && (G - B < 0))
43 H = ((2 * H) / 3) - 180;
44 }
45
46 java.text.DecimalFormat df = new java.text.DecimalFormat ("#.###");
47 String strRet = df.format(H) + "," + df.format(C) + "," + df.format(L);
48
49 return strRet;
50 }
Pengiriman parameter ke function/method RGB_HCL diatas adalah nilai RGB contoh
: 65, 27, 234, dan parameter Gamma. Gamma berada dalam jangkauan [0,31].
Output dari function/method ini akan berupa data HCL bertipe string, contoh : -
106.13, 0.56, 0.477.
II.10 TRANSFORMASI HCL KE RGB
Untuk transformasi kembali dari HCL ke RGB [Madenda and Missaoui, 2005],
dilakukan dalam dua tahap. tahap pertama adalah menghitung Q, Max dan Min :
4 3 3
4 2 2
4 3
4 2
kemudian mengecek nilai H (hue) :
Jika, 00 ≤ H ≤ 600
R = Max, B = Min
tan
1
Jika, 600 < H ≤ 1200
G = Max, B = Min
1 tan
tan
Jika, 1200 < H ≤ 1800 G = Max, R = Min 180
1 180
Jika, -600 ≤ H < 00
R = Max, G = Min
1
56
Jika, -1200 ≤ H < -600 B = Max, G = Min
Jika, -1800 < H < -1200
1 tan
tan
B = Max, R = Min
tan
1 tan
Transformasikan HCL(-106.130, 0.56, 0.477) ke dalam bentuk RGB, maka
langkahnya adalah sebagai berikut :
parameter γ (Gamma) = 30. Sesuai dengan parameter yang kita ambil sebelumnya
saat transformasi dari RGB ke HCL.
Q= . . 1.0367
.
Max = . . . 0.916
. .
Min = . . 0.106
.
Karena, H = -106.130 > -600, dan H ≤ -1200, maka
B = Max = 0.916,
G = Min = 0.106
1 tan 0.106 1 tan . – 0.916
tan tan . 0.312
sehingga nilai HCL(-106.130, 0.56, 0.477) ditransformasikan menjadi RGB(0.312,
0.106, 0.916) dengan jangkauan RGB [0,1]. Kalikan dengan 255 menjadi : (0.312 x
255, 0.106 x 255, 0.916 x 255) menjadi (79.56, 27,03, 233.58) bulatkan keatas
menjadi (80, 27, 234).
Berdasarkan langkah-langkah transformasi diatas, maka untuk
mengimplementasikan ke bahasa pemrograman adalah sebagai berikut :
57
II.10.A VISUAL BASIC 6 58
0 Private Function HCL_RGB(HCL As String, Gamma As Double) As String
1 Dim strData() As String
2 Const PI As Double = 3.14159265358979
3 Dim R As Double, G As Double, B As Double
4
5 strData = Split(HCL, ",")
6 If UBound(strData) >= 2 Then
7 Dim Q As Double, max As Double, min As Double
8 Dim H As Double, C As Double, L As Double
9 Dim tanH As Double
10
11 H = CDbl(strData(0))
12 C = CDbl(strData(1))
13 L = CDbl(strData(2))
14
15 Q = Exp((1 - (3 * C) / (4 * L)) * (Gamma / 100))
16 min = ((4 * L) - (3 * C)) / ((4 * Q) - 2)
17 max = (3 * C) / (2 * Q)
18 max = min + max
19
20 If H >= 0 And H <= 60 Then
21 tanH = Tan(H * 1.5 * PI / 180)
22 R = max
23 B = min
24 G = ((R * tanH) + B) / (1 + tanH)
25 ElseIf H > 60 And H <= 120 Then
26 H = H - 180
27 tanH = Tan(H * 0.75 * PI / 180)
28 G = max
29 B = min
30 R = ((G * (1 + tanH)) - B) / tanH
31 ElseIf H > 120 And H <= 180 Then
32 H = H - 180
33 tanH = Tan(H * 0.75 * PI / 180)
34 G = max
35 R = min
36 B = (G * (1 + tanH)) - (R * tanH)
37 ElseIf H >= -60 And H < 0 Then
38 tanH = Tan(H * 0.75 * PI / 180)
39 R = max
40 G = min
41 B = (G * (1 + tanH)) - (R * tanH)
42 ElseIf H >= -120 And H < -60 Then
43 tanH = Tan(H * 0.75 * PI / 180)
44 B = max
45 G = min
46 R = ((G * (1 + tanH)) - B) / tanH
47 ElseIf H > -180 And H < -120 Then
48 H = H + 180
49 tanH = Tan(H * 1.5 * PI / 180)
50 B = max
51 R = min
52 G = ((R * tanH) + B) / (1 + tanH)
53 End If
54
55 R = Round(R * 255)
56 G = Round(G * 255)
57 B = Round(B * 255)
58 End If
59
60 HCL_RGB = Format$(R, "###") + "," + Format$(G, "###") + "," + Format$(B, "###")
61 End Function
II.10.A VISUAL BASIC.NET
0 Private Function HCL_RGB(ByVal HCL As String, ByVal Gamma As Double) As String
1 Dim strData() As String
2 Const PI As Double = 3.14159265358979
3 Dim R As Double, G As Double, B As Double
4
5 strData = HCL.Split(",")
6 If strData.Length >= 3 Then
7 Dim Q As Double, max As Double, min As Double
8 Dim H As Double, C As Double, L As Double
9 Dim tanH As Double
10
11 H = Double.Parse(strData(0))
12 C = Double.Parse(strData(1))
13 L = Double.Parse(strData(2))
14
15 Q = Math.Exp((1 ‐ (3 * C) / (4 * L)) * (Gamma / 100))
16 min = ((4 * L) ‐ (3 * C)) / ((4 * Q) ‐ 2)
17 max = (3 * C) / (2 * Q)
18 max = min + max
19
20 If H >= 0 And H <= 60 Then
21 tanH = Math.Tan(H * 1.5 * PI / 180)
22 R = max
23 B = min
24 G = ((R * tanH) + B) / (1 + tanH)
25 ElseIf H > 60 And H <= 120 Then
26 H = H ‐ 180
27 tanH = Math.Tan(H * 0.75 * PI / 180)
28 G = max
29 B = min
30 R = ((G * (1 + tanH)) ‐ B) / tanH
31 ElseIf H > 120 And H <= 180 Then
32 H = H ‐ 180
33 tanH = Math.Tan(H * 0.75 * PI / 180)
34 G = max
35 R = min
36 B = (G * (1 + tanH)) ‐ (R * tanH)
37 ElseIf H >= ‐60 And H < 0 Then
38 tanH = Math.Tan(H * 0.75 * PI / 180)
39 R = max
40 G = min
59
41 B = (G * (1 + tanH)) ‐ (R * tanH)
42 ElseIf H >= ‐120 And H < ‐60 Then
43 tanH = Math.Tan(H * 0.75 * PI / 180)
44 B = max
45 G = min
46 R = ((G * (1 + tanH)) ‐ B) / tanH
47 ElseIf H > ‐180 And H < ‐120 Then
48 H = H + 180
49 tanH = Math.Tan(H * 1.5 * PI / 180)
50 B = max
51 R = min
52 G = ((R * tanH) + B) / (1 + tanH)
53 End If
54
55 R = Math.Round(R * 255)
56 G = Math.Round(G * 255)
57 B = Math.Round(B * 255)
58 End If
59
60 HCL_RGB = R.ToString("###") + "," + G.ToString("###") + "," + B.ToString("###")
61 End Function
II.10.A C# 60
0 private string HCL_RGB(string HCL, double Gamma)
1 {
2 string[] strData;
3 const double PI = 3.14159265358979;
4 double R=0, G=0, B=0;
5
6 strData = HCL.Split(',');
7 if (strData.Length >= 3)
8 {
9 double Q, max, min;
10 double H, C, L;
11 double tanH;
12
13 H = double.Parse(strData[0]);
14 C = double.Parse(strData[1]);
15 L = double.Parse(strData[2]);
16
17 Q = Math.Exp((1 ‐ (3 * C) / (4 * L)) * (Gamma / 100));
18 min = ((4 * L) ‐ (3 * C)) / ((4 * Q) ‐ 2);
19 max = (3 * C) / (2 * Q);
20 max = min + max;
21
22 if (H >= 0 && H <= 60)
23 {
24 tanH = Math.Tan(H * 1.5 * PI / 180);
25 R = max;
26 B = min;
27 G = ((R * tanH) + B) / (1 + tanH);
28 }
29 else if (H > 60 && H <= 120)
30 {
31 H = H ‐ 180;
32 tanH = Math.Tan(H * 0.75 * PI / 180);
33 G = max;
34 B = min;
35 R = ((G * (1 + tanH)) ‐ B) / tanH;
36 }
37 else if (H > 120 && H <= 180)
38 {
39 H = H ‐ 180;
40 tanH = Math.Tan(H * 0.75 * PI / 180);
41 G = max;
42 R = min;
43 B = (G * (1 + tanH)) ‐ (R * tanH);
44 }
45 else if ( H >= ‐60 && H < 0)
46 {
47 tanH = Math.Tan(H * 0.75 * PI / 180);
48 R = max;
49 G = min;
50 B = (G * (1 + tanH)) ‐ (R * tanH);
51 }
52 else if ( H >= ‐120 && H < ‐60)
53 {
54 tanH = Math.Tan(H * 0.75 * PI / 180);
55 B = max;
56 G = min;
57 R = ((G * (1 + tanH)) ‐ B) / tanH;
58 }
59 else if ( H > ‐180 && H < ‐120)
60 {
61 H = H + 180;
62 tanH = Math.Tan(H * 1.5 * PI / 180);
63 B = max;
64 R = min;
65 G = ((R * tanH) + B) / (1 + tanH);
66 }
67
68 R = Math.Round(R * 255);
69 G = Math.Round(G * 255);
70 B = Math.Round(B * 255);
71 }
72
73 return R.ToString("###") + "," + G.ToString("###") + "," + 74B.ToString("###");
75 }
II.10.A JAVA 61
0 private String HCL_RGB(String HCL, double Gamma)
1{
2 String[] strData;
3 double PI = 3.14159265358979;
4 double R=0, G=0, B=0;
5
6 strData = HCL.split(",");
7 if (strData.length >= 2) 62
8{
9 double Q, max, min;
10 double H, C, L;
11 double tanH;
12
13 H = Double.parseDouble(strData[0]);
14 C = Double.parseDouble(strData[1]);
15 L = Double.parseDouble(strData[2]);
16
17 Q = Math.exp((1 - (3 * C) / (4 * L)) * (Gamma / 100));
18 min = ((4 * L) - (3 * C)) / ((4 * Q) - 2);
19 max = (3 * C) / (2 * Q);
20 max = min + max;
21
22 if (H >= 0 && H <= 60)
23 {
24 tanH = Math.tan(H * 1.5 * PI / 180);
25 R = max;
26 B = min;
27 G = ((R * tanH) + B) / (1 + tanH);
28 }
29 else if (H > 60 && H <= 120)
30 {
31 H = H - 180;
32 tanH = Math.tan(H * 0.75 * PI / 180);
33 G = max;
34 B = min;
35 R = ((G * (1 + tanH)) - B) / tanH;
36 }
37 else if (H > 120 && H <= 180)
38 {
39 H = H - 180;
40 tanH = Math.tan(H * 0.75 * PI / 180);
41 G = max;
42 R = min;
43 B = (G * (1 + tanH)) - (R * tanH);
44 }
45 else if ( H >= -60 && H < 0)
46 {
47 tanH = Math.tan(H * 0.75 * PI / 180);
48 R = max;
49 G = min;
50 B = (G * (1 + tanH)) - (R * tanH);
51 }
52 else if ( H >= -120 && H < -60)
53 {
54 tanH = Math.tan(H * 0.75 * PI / 180);
55 B = max;
56 G = min;
57 R = ((G * (1 + tanH)) - B) / tanH;
58 }
59 else if ( H > -180 && H < -120)
60 {
61 H = H + 180;
62 tanH = Math.tan(H * 1.5 * PI / 180);
63 B = max;
64 R = min;
65 G = ((R * tanH) + B) / (1 + tanH);
66 }
67
68 R = Math.round(R * 255);
69 G = Math.round(G * 255);
70 B = Math.round(B * 255);
71 }
72
73 java.text.DecimalFormat df = new java.text.DecimalFormat ("###");
74 String strRet = df.format(R) + "," + df.format(G) + "," + df.format(B);
75 return strRet;
76 }
HCL terdiri dari bilangan Hue, Chroma dan Luminance, dan parameter Gamma.
Gamma berada dalam jangkauan [0,31], nilai parameter ini harus sama dengan nilai
saat di transformasi awal dari RGB ke HCL. Untuk memasukkan bilangan HCL ke
function/method HCL_RGB diatas, data dipisahkan oleh tanda koma (,), jadi contoh
pengiriman parameter ke function/method HCL_RGB diatas adalah -106.13, 0.56,
0.477 untuk parameter pertama dan 30 untuk parameter kedua. Output dari
function ini akan berupa data RGB bertipe string, contoh : 80, 27, 234.
II.11 TRANSFORMASI RGB KE YUV DAN YUV KE RGB
Untuk mentransformasi dari RGB ke YUV. Diasumsikan koordinat-koordinat R, G, B
[0,1] adalah berurutan merah, hijau, biru dalam ruang warna RGB, menggunakan
rumus seperti berikut : (sumber : http://en.wikipedia.org/wiki/YUV)
0.299 0.587 0.114
0.436 0.886
0.615 0.701
Untuk transformasi kembali dari YUV ke RGB, gunakan rumus berikut :
1.254
0.395 0.58
2.03
Berdasarkan rumus transformasi diatas, maka untuk mengimplementasikan ke
bahasa pemrograman adalah sebagai berikut :
63
II.11.A VISUAL BASIC 6 64
0 Private Function RGB_YUV(RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, U As Double, V As Double
3
4 strData = Split(RGB, ",")
5 If UBound(strData) >= 2 Then
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11
12 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
13 U = 0.436 * ((B - Y) / 0.886)
14 V = 0.615 * ((R - Y) / 0.701)
15 End If
16
17 RGB_YUV = Format$(Y, "0.000") + "," + Format$(U, "0.000") + _
18 "," + Format$(V, "0.000")
19 End Function
0 Private Function YUV_RGB(YUV As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = Split(YUV, ",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, U As Double, V As Double
7
8 Y = CDbl(strData(0))
9 U = CDbl(strData(1))
10 V = CDbl(strData(2))
11
12 R = Round((Y + (V * 1.254)) * 255)
13 G = Round((Y - (U * 0.395) - (V * 0.58)) * 255)
14 B = Round((Y + (U * 2.03)) * 255)
15 End If
16
17 YUV_RGB = Format$(R, "###") + "," + Format$(G, "###") + _
18 "," + Format$(B, "###")
19 End Function
II.11.B VISUAL BASIC.NET
0 Private Function RGB_YUV(ByVal RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, U As Double, V As Double
3
4 strData = RGB.Split(",")
5 If strData.Length >= 3 Then 65
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
12 U = 0.436 * ((B - Y) / 0.886)
13 V = 0.615 * ((R - Y) / 0.701)
14 End If
15
16 Return Y.ToString("0.000") + "," + U.ToString("0.000") + _
17 "," + V.ToString("0.000")
18 End Function
0 Private Function YUV_RGB(ByVal YUV As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = strData = YUV.Split(",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, U As Double, V As Double
7
8 Y = CDbl(strData(0))
9 U = CDbl(strData(1))
10 V = CDbl(strData(2))
11
12 R = Math.Round((Y + (V * 1.254)) * 255)
13 G = Math.Round((Y - (U * 0.395) - (V * 0.58)) * 255)
14 B = Math.Round((Y + (U * 2.03)) * 255)
15 End If
16
17 Return R.ToString("###") + "," + G.ToString("###") + _
18 "," + B.ToString("###")
19 End Function
II.11.C C#
0 private string RGB_YUV(string RGB)
1{
2 string[] strData;
3 double Y=0, U=0, V=0;
4
5 strData = RGB.Split(',');
6 if (strData.Length >= 3)
7{
8 double R, G, B;
9
10 R = double.Parse(strData[0]) / 255;
11 G = double.Parse(strData[1]) / 255;
12 B = double.Parse(strData[2]) / 255;
13
14 Y = (0.299 * R) + (0.587 * G) + (0.114 * B); 66
15 U = 0.436 * ((B - Y) / 0.886);
16 V = 0.615 * ((R - Y) / 0.701);
17 }
18
19 return Y.ToString("0.000") + "," + U.ToString("0.000") +
20 "," + V.ToString("0.000");
21 }
0 private string YUV_RGB(string YUV)
1{
2 string[] strData;
3 double R=0, G=0, B=0;
4
5 strData = YUV.Split(',');
6 if (strData.Length >= 3)
7{
8 double Y, U, V;
9
10 Y = double.Parse(strData[0]);
11 U = double.Parse(strData[1]);
12 V = double.Parse(strData[2]);
13
14 R = Math.Round((Y + (V * 1.254)) * 255);
15 G = Math.Round((Y - (U * 0.395) - (V * 0.58)) * 255);
16 B = Math.Round((Y + (U * 2.03)) * 255);
17 }
18
19 return R.ToString("###") + "," + G.ToString("###") +
20 "," + B.ToString("###");
21 }
II.11.D JAVA
0 private String RGB_YUV(String RGB)
1{
2 String[] strData;
3 String strRet = "";
4 double Y=0, U=0, V=0;
5
6 strData = RGB.split(",");
7 if (strData.length >= 2)
8{
9 double R, G, B;
10
11 R = Double.parseDouble(strData[0] / 255);
12 G = Double.parseDouble(strData[1] / 255);
13 B = Double.parseDouble(strData[2] / 255);
14
15 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
16 U = 0.436 * ((B - Y) / 0.886);
17 V = 0.615 * ((R - Y) / 0.701);
18
19 java.text.DecimalFormat df = new java.text.DecimalFormat ("0.000");
20 strRet = df.format(Y) + "," + df.format(U) + "," + df.format(V);
21 }
22 return strRet;
23 }
0 private static String YUV_RGB(String YUV)
1{
2 String[] strData;
3 String strRet = "";
4 double R=0, G=0, B=0;
5
6 strData = YUV.split(",");
7 if (strData.length >= 2)
8{
9 double Y, U, V;
10 Y = Double.parseDouble(strData[0]);
11 U = Double.parseDouble(strData[1]);
12 V = Double.parseDouble(strData[2]);
13
14 R = Math.round((Y + (V * 1.254)) * 255);
15 G = Math.round((Y - (U * 0.395) - (V * 0.58)) * 255);
16 B = Math.round((Y + (U * 2.03)) * 255);
17
18 java.text.DecimalFormat df = new java.text.DecimalFormat ("###");
19 strRet = df.format(R) + "," + df.format(G) + "," + df.format(B);
20 }
21 return strRet;
22 }
Pengiriman parameter ke function/method RGB_YUV diatas adalah nilai RGB contoh
: 65, 27, 234. Output dari function/method ini akan berupa data YUV bertipe string,
contoh : 0.243,0.332,0.010. Dan sebaliknya untuk function/method YUV_RGB
menerima parameter nilai YUV, dan menghasilkan nilai RGB.
II.12 TRANSFORMASI RGB KE YDbDr dan YDbDr KE RGB
Untuk mentransformasi dari RGB ke YDbDr. Diasumsikan koordinat-koordinat
R, G, B [0,1] adalah berurutan merah, hijau, biru dalam ruang warna RGB dan
Db, Dr[-1.333, 1.333] menggunakan rumus seperti berikut :
(http://en.wikipedia.org/wiki/YDbDr)
Y = 0.299R + 0.587G + 0.114B
Db = -045R – 0.883G + 1.333B
Dr = -1.333R + 1.116G + 0.217B
67
Untuk transformasi kembali dari YDbDr ke RGB, gunakan rumus berikut :
R = Y + 0.000092303716148Db - 0.525912630661865Dr
G = Y - 0.129132898890509Db + 0.267899328207599Dr
B = Y + 0.664679059978955Db - 0.000079202543533Dr
Berdasarkan rumus transformasi diatas, maka untuk mengimplementasikan ke
bahasa pemrograman adalah sebagai berikut :
II.12.A VISUAL BASIC 6
0 Private Function RGB_YDbDr(RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, Db As Double, Dr As Double
3
4 strData = Split(RGB, ",")
5 If UBound(strData) >= 2 Then
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
12 Db = (-0.45 * R) - (0.883 * G) + (1.333 * B)
13 Dr = (-1.333 * R) + (1.116 * G) + (0.217 * B)
14 End If
15 RGB_YDbDr = Format$(Y, "0.000") + "," + Format$(Db, "0.000") + "," + Format$(Dr, "0.000")
16 End Function
0 Private Function YDbDr_RGB(YDbDr As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = Split(YDbDr, ",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, Db As Double, Dr As Double
7
8 Y = CDbl(strData(0))
9 Db = CDbl(strData(1))
10 Dr = CDbl(strData(2))
11 R = Y + (0.000092303716148 * Db) - (0.525912630661865 * Dr)
12 R = Round(R * 255)
13 G = Y - (0.129132898890509 * Db) + (0.267899328207599 * Dr)
14 G = Round(G * 255)
15 B = Y + (0.664679059978955 * Db) - (0.000079202543533 * Dr)
16 B = Round(B * 255)
17 End If
18 YDbDr_RGB = Format$(R, "###") + "," + Format$(G, "###") + "," + Format$(B, "###")
19 End Function
68
II.12.B VISUAL BASIC.NET
0 Private Function RGB_YDbDr(ByVal RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, Db As Double, Dr As Double
3
4 strData = RGB.Split(",")
5 If strData.Length >= 3 Then
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11
12 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
13 Db = (-0.45 * R) - (0.883 * G) + (1.333 * B)
14 Dr = (-1.333 * R) + (1.116 * G) + (0.217 * B)
15 End If
16
17 Return Y.ToString("0.000") + "," + Db.ToString("0.000") + "," + Dr.ToString("0.000")
18 End Function
0 Private Function YDbDr_RGB(ByVal YDbDr As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = YDbDr.Split(",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, Db As Double, Dr As Double
7
8 Y = CDbl(strData(0))
9 Db = CDbl(strData(1))
10 Dr = CDbl(strData(2))
11
12 R = Y + (0.000092303716148 * Db) - (0.525912630661865 * Dr)
13 R = Math.Round(R * 255)
14 G = Y - (0.129132898890509 * Db) + (0.267899328207599 * Dr)
15 G = Math.Round(G * 255)
16 B = Y + (0.664679059978955 * Db) - (0.000079202543533 * Dr)
17 B = Math.Round(B * 255)
18 End If
19
20 Return R.ToString("###") + "," + G.ToString("###") + "," + B.ToString("###")
21 End Function
69
II.12.C C#
0 private string RGB_YDbDr(string RGB)
1{
2 string[] strData;
3 double Y = 0, Db = 0, Dr = 0;
4
5 strData = RGB.Split(',');
6 if (strData.Length >= 3)
7{
8 double R, G, B;
9
10 R = double.Parse(strData[0]) / 255;
11 G = double.Parse(strData[1]) / 255;
12 B = double.Parse(strData[2]) / 255;
13
14 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
15 Db = (-0.45 * R) - (0.883 * G) + (1.333 * B);
16 Dr = (-1.333 * R) + (1.116 * G) + (0.217 * B);
17 }
18
19 return Y.ToString("0.000") + "," + Db.ToString("0.000") + "," + Dr.ToString("0.000");
20 }
0 private string YDbDr_RGB(string YDbDr)
1{
2 string[] strData;
3 double R = 0, G = 0, B = 0;
4
5 strData = YDbDr.Split(',');
6 if (strData.Length >= 3)
7{
8 double Y, Db, Dr;
9
10 Y = double.Parse(strData[0]) / 255;
11 Db = double.Parse(strData[1]) / 255;
12 Dr = double.Parse(strData[2]) / 255;
13
14 R = Y + (0.000092303716148 * Db) - (0.525912630661865 * Dr);
15 R = Math.Round(R * 255);
16 G = Y - (0.129132898890509 * Db) + (0.267899328207599 * Dr);
17 G = Math.Round(G * 255);
18 B = Y + (0.664679059978955 * Db) - (0.000079202543533 * Dr);
19 B = Math.Round(B * 255);
20 }
21
22 return R.ToString("###") + "," + G.ToString("###") + "," + B.ToString("###");
23 }
70
II.12.D JAVA 71
0 private String RGB_YDbDr(String RGB)
1{
2 String[] strData;
3 String strRet = "";
4 double Y=0, Db=0, Dr=0;
5
6 strData = RGB.split(",");
7 if (strData.length >= 2)
8{
9 double R, G, B;
10
11 R = Double.parseDouble(strData[0]) / 255;
12 G = Double.parseDouble(strData[1]) / 255;
13 B = Double.parseDouble(strData[2]) / 255;
14 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
15 Db = (-0.45 * R) - (0.883 * G) + (1.333 * B);
16 Dr = (-1.333 * R) + (1.116 * G) + (0.217 * B);
17
18 java.text.DecimalFormat df = new java.text.DecimalFormat ("0.000");
19 strRet = df.format(Y) + "," + df.format(Db) + "," + df.format(Dr);
20 }
21 return strRet;
22 }
0 private static String YDbDr_RGB(String YDbDr)
1{
2 String[] strData;
3 String strRet = "";
4 double R=0, G=0, B=0;
5
6 strData = YDbDr.split(",");
7 if (strData.length >= 2)
8{
9 double Y, Db, Dr;
10
11 Y = Double.parseDouble(strData[0]);
12 Db = Double.parseDouble(strData[1]);
13 Dr = Double.parseDouble(strData[2]);
14
15 R = Y + (0.000092303716148 * Db) - (0.525912630661865 * Dr);
16 R = Math.round(R * 255);
17 G = Y - (0.129132898890509 * Db) + (0.267899328207599 * Dr);
18 G = Math.round(G * 255);
19 B = Y + (0.664679059978955 * Db) - (0.000079202543533 * Dr);
20 B = Math.round(B * 255);
21
22 java.text.DecimalFormat df = new java.text.DecimalFormat ("###");
23 strRet = df.format(R) + "," + df.format(G) + "," + df.format(B);
24 }
25 return strRet;
26 }
Pengiriman parameter ke function/method RGB_YDbDr diatas adalah nilai RGB
contoh : 65, 27, 234. Output dari function/method ini akan berupa data YDbDr
bertipe string, contoh : 0.243, 1.015, -0.022. Dan juga sebaliknya untuk
function/method YDbDr_RGB menerima parameter nilai YDbDr, dan mengembalikan
nilai berupa nilai RGB.
II.13 TRANSFORMASI RGB KE YIQ DAN YIQ KE RGB (NTSC)
Untuk mentransformasi dari RGB ke YIQ. Diasumsikan koordinat-koordinat R, G, B
[0,1] adalah berurutan merah, hijau, biru dalam ruang warna RGB dan I [-0.5957,
0.5957], Dr [-0.5226, 0.5226] menggunakan rumus seperti berikut : (sumber :
http://en.wikipedia.org/wiki/YIQ)
Y = 0.299R + 0.587G + 0.114B
I = 0.595716R – 0.274453G – 0.321263B
Q = 0.211456R – 0.522591G + 0.311135B
Untuk transformasi kembali dari YIQ ke RGB, gunakan rumus berikut :
R = Y + 0.9563I + 0.6210Q
G = Y – 0.2721I – 0.6474Q
B = Y – 1.1070I + 1.7046Q
Berdasarkan rumus transformasi diatas, maka untuk mengimplementasikan ke
bahasa pemrograman adalah sebagai berikut :
II.13.A VISUAL BASIC 6
0 Private Function RGB_YIQ(RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, I As Double, Q As Double
3
4 strData = Split(RGB, ",")
5 If UBound(strData) >= 2 Then
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11
12 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
13 I = (0.595716 * R) - (0.274453 * G) - (0.321263 * B)
14 Q = (0.211456 * R) - (0.522591 * G) + (0.311135 * B)
15 End If
16
17 RGB_YIQ = Format$(Y, "0.000") + "," + Format$(I, "0.000") + "," + Format$(Q, "0.000")
18 End Function
72
0 Private Function YIQ_RGB(YIQ As String) As String 73
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = Split(YIQ, ",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, I As Double, Q As Double
7
8 Y = CDbl(strData(0))
9 I = CDbl(strData(1))
10 Q = CDbl(strData(2))
11
12 R = Y + (0.9563 * I) + (0.621 * Q)
13 R = Round(R * 255)
14 G = Y - (0.2721 * I) - (0.6474 * Q)
15 G = Round(G * 255)
16 B = Y - (1.107 * I) + (1.7046 * Q)
17 B = Round(B * 255)
18 End If
19
20 YIQ_RGB = Format$(R, "###") + "," + Format$(G, "###") + "," + Format$(B, "###")
21 End Function
II.13.B VISUAL BASIC.NET
0 Private Function RGB_YIQ(ByVal RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, I As Double, Q As Double
3
4 strData = RGB.Split(",")
5 If strData.Length >= 3 Then
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11
12 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
13 I = (0.595716 * R) - (0.274453 * G) - (0.321263 * B)
14 Q = (0.211456 * R) - (0.522591 * G) + (0.311135 * B)
15 End If
16
17 Return Y.ToString("0.000") + "," + I.ToString("0.000") + _
18 "," + Q.ToString("0.000")
19 End Function
0 Private Function YIQ_RGB(ByVal YIQ As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = YIQ.Split(",")
5 If UBound(strData) >= 2 Then 74
6 Dim Y As Double, I As Double, Q As Double
7
8 Y = CDbl(strData(0))
9 I = CDbl(strData(1))
10 Q = CDbl(strData(2))
11
12 R = Y + (0.9563 * I) + (0.621 * Q)
13 R = Math.Round(R * 255)
14 G = Y - (0.2721 * I) - (0.6474 * Q)
15 G = Math.Round(G * 255)
16 B = Y - (1.107 * I) + (1.7046 * Q)
17 B = Math.Round(B * 255)
18 End If
19
20 Return R.ToString("###") + "," + G.ToString("###") + _
21 "," + B.ToString("###")
22 End Function
II.13.C C#
0 private string RGB_YIQ(string RGB)
1{
2 string[] strData;
3 double Y = 0, I = 0, Q = 0;
4
5 strData = RGB.Split(',');
6 if (strData.Length >= 3)
7{
8 double R, G, B;
9
10 R = double.Parse(strData[0]) / 255;
11 G = double.Parse(strData[1]) / 255;
12 B = double.Parse(strData[2]) / 255;
13
14 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
15 I = (0.595716 * R) - (0.274453 * G) - (0.321263 * B);
16 Q = (0.211456 * R) - (0.522591 * G) + (0.311135 * B);
17 }
18
19 return Y.ToString("0.000") + "," + I.ToString("0.000") +
20 "," + Q.ToString("0.000");
21 }
0 private string YIQ_RGB(string YIQ)
1{
2 string[] strData;
3 double R = 0, G = 0, B = 0;
4
5 strData = YIQ.Split(',');
6 if (strData.Length >= 3)
7{ 75
8 double Y, I, Q;
9
10 Y = double.Parse(strData[0]);
11 I = double.Parse(strData[1]);
12 Q = double.Parse(strData[2]);
13
14 R = Y + (0.9563 * I) + (0.621 * Q);
15 R = Math.Round(R * 255);
16 G = Y - (0.2721 * I) - (0.6474 * Q);
17 G = Math.Round(G * 255);
18 B = Y - (1.107 * I) + (1.7046 * Q);
19 B = Math.Round(B * 255);
20 }
21
22 return R.ToString("###") + "," + G.ToString("###") +
23 "," + B.ToString("###");
24 }
II.13.D JAVA
0 private String RGB_YIQ(String RGB)
1{
2 String[] strData;
3 String strRet = "";
4 double Y=0, I=0, Q=0;
5
6 strData = RGB.split(",");
7 if (strData.length >= 2)
8{
9 double R, G, B;
10
11 R = Double.parseDouble(strData[0]) / 255;
12 G = Double.parseDouble(strData[1]) / 255;
13 B = Double.parseDouble(strData[2]) / 255;
14
15 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
16 I = (0.595716 * R) - (0.274453 * G) - (0.321263 * B);
17 Q = (0.211456 * R) - (0.522591 * G) + (0.311135 * B);
18
19 java.text.DecimalFormat df = new java.text.DecimalFormat ("0.000");
20 strRet = df.format(Y) + "," + df.format(I) + "," + df.format(Q);
21 }
22 return strRet;
23 }
0 private static String YIQ_RGB(String YIQ)
1{
2 String[] strData;
3 String strRet = "";
4 double R=0, G=0, B=0;
5 strData = YIQ.split(",");
6 if (strData.length >= 2)
7{
8 double Y, I, Q;
9
10 Y = Double.parseDouble(strData[0]);
11 I = Double.parseDouble(strData[1]);
12 Q = Double.parseDouble(strData[2]);
13
14 R = Y + (0.9563 * I) + (0.621 * Q);
15 R = Math.round(R * 255);
16 G = Y - (0.2721 * I) - (0.6474 * Q);
17 G = Math.round(G * 255);
18 B = Y - (1.107 * I) + (1.7046 * Q);
19 B = Math.round(B * 255);
20
21 java.text.DecimalFormat df = new java.text.DecimalFormat ("###");
22 strRet = df.format(R) + "," + df.format(G) + "," + df.format(B);
23 }
24 return strRet;
25 }
Pengiriman parameter ke function/method RGB_YIQ diatas adalah nilai RGB contoh
: 65,27,234. Output dari function/method ini akan berupa data YIQ bertipe string,
contoh : 0.243, -0.172, 0.284. Dan juga sebaliknya untuk function/method YIQ_RGB
menerima parameter nilai YIQ, dan mengembalikan nilai berupa data RGB.
II.14 TRANSFORMASI RGB KE YCbCr DAN YCbCr KE RGB
YCbCr (256 level) dapat diperoleh dari RGB dengan menggunakan rumus berikut
(Hamilton,1992) :
Y = 0.299 R + 0.587 G + 0.114 B
Cb = - 0.1687 R - 0.3313 G + 0.5 B + 128
Cr = 0.5 R - 0.4187 G - 0.0813 B + 128
Sedangkan untuk konversi YCbCr ke RGB dapat dilakukan dengan rumus berikut
(Hamilton,1992) :
R = Y + 1.402 (Cr - 128)
G = Y - 0.34414 (Cb - 128) - 0.71414 (Cr - 128)
B = Y + 1.772 (Cb - 128)
Berdasarkan rumus transformasi diatas, maka untuk mengimplementasikan ke
bahasa pemrograman adalah sebagai berikut :
76
II.14.A VISUAL BASIC 6
0 Private Function RGB_YCbCr(RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, Cb As Double, Cr As Double
3
4 strData = Split(RGB, ",")
5 If UBound(strData) >= 2 Then
6 Dim R As Double, G As Double, B As Double
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11
12 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
13 Cb = (-0.1687 * R) - (0.3313 * G) + (0.5 * B) + 128
14 Cr = (0.5 * R) - (0.4187 * G) - (0.0813 * B) + 128
15 End If
16 RGB_YCbCr = Format$(Y, "0.000") + "," + Format$(Cb, "0.000") + "," + Format$(Cr, "0.000")
17 End Function
0 Private Function YCbCr_RGB(YCbCr As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = Split(YCbCr, ",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, Cb As Double, Cr As Double
7
8 Y = CDbl(strData(0))
9 Cb = CDbl(strData(1))
10 Cr = CDbl(strData(2))
11 R = Y + (1.402 * (Cr - 128))
12 R = Round(R * 255)
13 G = Y - (0.34414 * (Cb - 128)) - (0.71414 * (Cr - 128))
14 G = Round(G * 255)
15 B = Y + (1.772 * (Cb - 128))
16 B = Round(B * 255)
17 End If
18
19 YCbCr_RGB = Format$(R, "###") + "," + Format$(G, "###") + "," + Format$(B, "###")
20 End Function
II.14.B VISUAL BASIC.NET 77
0 Private Function RGB_YCbCr(ByVal RGB As String) As String
1 Dim strData() As String
2 Dim Y As Double, Cb As Double, Cr As Double
3
4 strData = RGB.Split(",")
5 If strData.Length >= 3 Then
6 Dim R As Double, G As Double, B As Double 78
7
8 R = CDbl(strData(0)) / 255
9 G = CDbl(strData(1)) / 255
10 B = CDbl(strData(2)) / 255
11
12 Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
13 Cb = (-0.1687 * R) - (0.3313 * G) + (0.5 * B) + 128
14 Cr = (0.5 * R) - (0.4187 * G) - (0.0813 * B) + 128
15 End If
16
17 Return Y.ToString("0.000") + "," + Cb.ToString("0.000") + _
18 "," + Cr.ToString("0.000")
19 End Function
0 Private Function YCbCr_RGB(ByVal YCbCr As String) As String
1 Dim strData() As String
2 Dim R As Double, G As Double, B As Double
3
4 strData = YCbCr.Split(",")
5 If UBound(strData) >= 2 Then
6 Dim Y As Double, Cb As Double, Cr As Double
7
8 Y = CDbl(strData(0))
9 Cb = CDbl(strData(1))
10 Cr = CDbl(strData(2))
11
12 R = Y + (1.402 * (Cr - 128))
13 R = Math.Round(R * 255)
14 G = Y - (0.34414 * (Cb - 128)) - (0.71414 * (Cr - 128))
15 G = Math.Round(G * 255)
16 B = Y + (1.772 * (Cb - 128))
17 B = Math.Round(B * 255)
18 End If
19
20 Return R.ToString("###") + "," + G.ToString("###") + _
21 "," + B.ToString("###")
22 End Function
II.14.C C#
0 private string RGB_YCbCr(string RGB)
1{
2 string[] strData;
3 double Y = 0, Cb = 0, Cr = 0;
4
5 strData = RGB.Split(',');
6 if (strData.Length >= 3)
7{
8 double R, G, B;
9
10 R = double.Parse(strData[0]) / 255;
11 G = double.Parse(strData[1]) / 255; 79
12 B = double.Parse(strData[2]) / 255;
13
14 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
15 Cb = (-0.1687 * R) - (0.3313 * G) + (0.5 * B) + 128;
16 Cr = (0.5 * R) - (0.4187 * G) - (0.0813 * B) + 128;
17 }
18
19 return Y.ToString("0.000") + "," + Cb.ToString("0.000") +
20 "," + Cr.ToString("0.000");
21 }
0 private string YCbCr_RGB(string YCbCr)
1{
2 string[] strData;
3 double R = 0, G = 0, B = 0;
4
5 strData = YCbCr.Split(',');
6 if (strData.Length >= 3)
7{
8 double Y, Cb, Cr;
9
10 Y = double.Parse(strData[0]);
11 Cb = double.Parse(strData[1]);
12 Cr = double.Parse(strData[2]);
13
14 R = Y + (1.402 * (Cr - 128));
15 R = Math.Round(R * 255);
16 G = Y - (0.34414 * (Cb - 128)) - (0.71414 * (Cr - 128));
17 G = Math.Round(G * 255);
18 B = Y + (1.772 * (Cb - 128));
19 B = Math.Round(B * 255);
20 }
21
22 return R.ToString("###") + "," + G.ToString("###") +
23 "," + B.ToString("###");
24 }
II.14.D JAVA
0 private static String RGB_YCbCr(String RGB)
1{
2 String[] strData;
3 String strRet = "";
4 double Y=0, Cb=0, Cr=0;
5
6 strData = RGB.split(",");
7 if (strData.length >= 2)
8{
9 double R, G, B;
10
11 R = Double.parseDouble(strData[0]) / 255;
12 G = Double.parseDouble(strData[1]) / 255;
13 B = Double.parseDouble(strData[2]) / 255;
14 Y = (0.299 * R) + (0.587 * G) + (0.114 * B);
15 Cb = (-0.1687 * R) - (0.3313 * G) + (0.5 * B) + 128;
16 Cr = (0.5 * R) - (0.4187 * G) - (0.0813 * B) + 128;
17
18 java.text.DecimalFormat df = new java.text.DecimalFormat ("0.000");
19 strRet = df.format(Y) + "," + df.format(Cb) + "," + df.format(Cr);
20 }
21 return strRet;
22 }
0 private String YCbCr_RGB(String YCbCr)
1{
2 String[] strData;
3 String strRet = "";
4 double R=0, G=0, B=0;
5
6 strData = YCbCr.split(",");
7 if (strData.length >= 2)
8{
9 double Y, Cb, Cr;
10
11 Y = Double.parseDouble(strData[0]);
12 Cb = Double.parseDouble(strData[1]);
13 Cr = Double.parseDouble(strData[2]);
14
15 R = Y + (1.402 * (Cr - 128));
16 R = Math.round(R * 255);
17 G = Y - (0.34414 * (Cb - 128)) - (0.71414 * (Cr - 128));
18 G = Math.round(G * 255);
19 B = Y + (1.772 * (Cb - 128));
20 B = Math.round(B * 255);
21
22 java.text.DecimalFormat df = new java.text.DecimalFormat ("###");
23 strRet = df.format(R) + "," + df.format(G) + "," + df.format(B);
24 }
25 return strRet;
26 }
Pengiriman parameter ke function/method RGB_YCbCr diatas adalah nilai RGB
contoh : 65, 27, 234. Output dari function/method ini akan berupa data YCbCr
bertipe string, contoh : 251.13, 0.756, 0.4257. Dan juga sebaliknya untuk
function/method YCbCr_RGB menerima parameter nilai YCbCr, dan mengembalikan
nilai berupa data RGB.
80
DAFTAR PUSTAKA
Cuturicu, C., 1999, A note about the JPEG decoding algorithm, http://
www.opennet.ru/ docs/ formats/ jpeg.txt.
Ford, A., dan Roberts, A., Agustus 1998, Colour Space Conversions,http://
www.inforamp.net/ ~poynton/ PDFs/ coloureq.pdf.
Gonzales and Woods, Digital Image Processing, 1st ed, Addison-Wesley, 1992.
Hamilton, E., September 1992, JPEG File Interchange Format, Version 1.02. http://
www.w3.org/ Graphics/ JPEG/ jfif.txt.
HSL and HSV, http://en.wikipedia.org/wiki/HSL_color_space.
M. Sarifuddin and Rokia Missaoui, HCL: a new Color Space for a more Effective
Content-based Image Retrieval, RESEARCH REPORT D´epartement d’informatique et
d’ing´enierie, Universit´e du Qu´ebec en Outaouais, C.P. 1250, Succ. B, Gatineau (Qc),
Canada, J8X 3X7., 2005
RGB Color Model, http://en.wikipedia.org/wiki/RGB_color_model.
81
LAMPIRAN A
MENGAMBIL NILAI RGB DARI CITRA
VISUAL BASIC 6
Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As
Long) As Long
0 Private Function GetRGBFromPos(pict As PictureBox, Width As Long, Height As Long)
1 Dim pixel As Long
2 Dim Red As Long, Green As Long, Blue As Long
3 Dim strRGB As String
4
5 pixel = GetPixel(pict.hDC, Width, Height)
6 'pixel = pict.Point(J, I)
7 Red = pixel And 255
8 Green = (pixel \ 256) And 255
9 Blue = (pixel \ 65536) And 255
10
11 GetRGBFromPos = CStr(Red) + ", " + CStr(Green) + ", " + CStr(Blue)
12 End Function
Prosedur diatas akan mendapatkan nilai RGB yang disimpan ke variabel Red, Green
dan Blue (di baris 7, 8 dan 8). Data citra diambil dari kontrol PictureBox.
GetPixel adalah fungsi API untuk mengambil data pixel, yang berjalan lebih cepat
dibandingkan dengan fungsi standard PictureBox pict.Point(J, I).
82
VISUAL BASIC.NET
0 Private Function GetRGBFromPos(ByVal filename As String, ByVal Width As Integer, _
1 ByVal Height As Integer) As String
2 Dim myBitmap As Bitmap = New Bitmap(filename)
3
4 If (Height > myBitmap.Height) Then Height = myBitmap.Height - 1
5 If (Width > myBitmap.Width) Then Width = myBitmap.Width - 1
6
7 Dim pixelColor As Color = myBitmap.GetPixel(Width, Height)
8
9 Return pixelColor.R.ToString() + ", " + pixelColor.G.ToString() + _
10 ", " + pixelColor.B.ToString()
11 End Function
C#
0 private string GetRGBFromPos(string filename, int Width, int Height)
1{
2 Bitmap myBitmap = new Bitmap(filename);
3 if (Height > myBitmap.Height) Height = myBitmap.Height-1;
4 if (Width > myBitmap.Width) Width = myBitmap.Width-1;
5
6 Color pixelColor = myBitmap.GetPixel(Width, Height);
7
8 return pixelColor.R.ToString() + ", " + pixelColor.G.ToString() +
9 ", " + pixelColor.B.ToString();
10 }
Prosedur diatas (Visual Basic.Net dan C#) akan mendapatkan nilai RGB yang
disimpan ke variabel Red, Green dan Blue (di baris 8). Data citra diambil dari file.
Ukuran citra yang sebenarnya terdapat di variabel myBitmap.Height dan
myBitmap.Width seperti di baris 3 dan 4.
Parameter filename (baris 0) adalah nama lengkap dari file citra, misalnya
c:\gambar\gambar1.jpg untuk visual basic.net dan c:\\gambar\\gambar1.jpg, untuk
c#.
83
JAVA
0 private String GetRGBFromPos(String filename, int x, int y)
1{
2 int red =0, green=0, blue=0, color=0;
3 try
4{
5 java.io.File file= new java.io.File(filename);
6
7 java.awt.image.BufferedImage image =
8 javax.imageio.ImageIO.read(file);
9
10 color = image.getRGB(x,y);
11
12 red = (color & 0x00ff0000) >> 16;
13 green = (color & 0x0000ff00) >> 8;
14 blue = color & 0x000000ff;
15 }
16 catch(Exception ex) { }
17
18 return String.valueOf(red) + ", " + String.valueOf(green) +
29 ", " + String.valueOf(blue);
30 }
Prosedur diatas akan mendapatkan nilai RGB yang disimpan ke variabel Red, Green
dan Blue (di baris 12, 13 dan 14). Data citra diambil dari file.
Parameter filename (baris 0) adalah nama lengkap dari file citra, misalnya
c:\\gambar\\gambar1.jpg.
84
LAMPIRAN B
TAMPILAN PROJECT
PROJECT TRANSFORMASI WARNA DI VISUAL BASIC 6
PROJECT TRANSFORMASI WARNA DI VISUAL BASIC.NET
85
PROJECT TRANSFORMASI WARNA DI C#
PROJECT TRANSFORMASI WARNA DI JAVA
Program-program diatas tersedia secara lengkap dalam CD yang disertakan di buku
ini.
86
ERICKS RACHMAT SWEDIA, ST, MMSI
PERSONAL DATA
Alamat : Pondok Bambu Kuning Blok B1/7, Bojonggede,
Bogor.
Telepon : 087878020802
Email : [email protected]
Posisi : Wakil Kepala sub Bagian Pengembangan Sistem,
Universitas Gunadarma
TEACHING EXPERIENCES
Algoritma dan Pemrograman I, Universitas Gunadarma (2009)
Konsep Data Mining, Universitas Gunadarma (2009)
Pengantar Kecerdasan Buatan, Universitas Gunadarma (2010)
Pengolahan Paralel, Universitas Gunadarma (2009)
Sistem Basis Data I, Universitas Gunadarma (2009)
INTERNATIONAL CERTIFICATION
2005 Microsoft Certified Professional in Developing Windows Applications with
Visual Basic.NET.
2005 Microsoft Certified Professional in Developing XML Web Services with
Visual Basic.NET.
2005 Microsoft Certified Professional in Implementing and Designing SQL Server.
2005 Microsoft Certified Professional in Developing Web Applications with
Visual Basic.NET.
2005 Microsoft Certified Applications Developer (MCAD.NET)
FORMAL EDUCATION
2005-2008 Master of Information System Management at Gunadarma University.
Thesis :
Design and Analysis Project Monitoring Control System at PT. Jalan
Tol Seksi Empat Makassar.
1994-1999 Bachelor Degree at Gunadarma University, Faculty of Industry
Technology, Department of Information Technique.
Thesis :
Designing and Programming The Deterministic Turing Machine
Simulator
87
PROJECTS EXPERIENCE
2000 Developed Chief Election Application for KOPERTIS III Jakarta with Windows
Socket (TCP/IP).
Part of a team in developing Project Monitoring Information System for
Departemen Dalam Negeri Indonesia.
Part of a team in developing Investment Information System for Departemen
Dalam Negeri Indonesia.
Part of a team in developing Voucher System Application for IT Division PT.
Bristol Myers Squibb Indonesia Tbk.
2001 Developed Exam Application for Gunadarma University.
Part of a team in Analyze Technological and Professional Skill Development
Project for Dirjen Pendidikan Tinggi (DIKTI) Indonesia.
Developed Transcript Application and System for Gunadarma University.
2002 Developed Product Scheduler Application for PPIC Division PT. Bristol Myers
Squibb Indonesia Tbk.
Developed Task Remainder Application for PPIC Division PT. Bristol Myers
Squibb Indonesia Tbk.
Developed Asessment Result Application for Human Resource division,
Departement Kehutanan Republik Indonesia.
2004 Developed Sales-Distributor Report Application for Sales Division PT. Nestle
Indonesia.
2005 Developed Academic Application for Gunadarma University.
Developed Radio Application and System for Megaswara Radio (Bogor, Serang,
Sukabumi, Kuningan).
2006 Developed Malaysian Derivative Exchange Interpreter for Bernama with TCP/IP
and Serial Communications (COMM).
Developed Kuala Lumpur Stock Exchange Interpreter for Bernama with Serial
Communications (COMM).
Developed Unit Trust Web Application for Bernama.
2007 Developed Academic Application for Akademi Kebidanan Gunadarma
University.
Developed Chess Application for Gunadarma University.
Developed Project Monitoring Control System for PT. Jalan Tol Seksi IV -
Makassar.
Developed Crude Oil Import Monitoring for Crude & Intermediate Procurement
Department PT. Pertamina - Jakarta.
2009 Developed Report Management for MetroTV.
2010 Developed Oil Publication for PT. Pertamina - Jakarta.
I hereby certify that the information given above is true. Under any circumstances
where misrepresentation or omission of information is found, I understand that I shall
be fully responsible.
88
MARGI CAHYANTI, SKom, MMSI
PERSONAL DATA
Alamat : Pondok Bambu Kuning Blok B1/7,
Bojonggede, Bogor.
Telepon : 087878020820
Email : [email protected]
Posisi : Kepala Bagian Ujian Mandiri,
Universitas Gunadarma
Alamat Kantor : Jl. Margonda Raya No. 100 Depok
Telepon Kantor : 021-78881112 ext. 501
TEACHING EXPERIENCES
Algoritma Pemrograman I, STMIK Gunadarma (1993 - 1995)
Pemrograman Pascal I, STMIK Gunadarma (1993 - 1995)
Pengantar Komputer dan TI II, Universitas Gunadarma (2000 - 2002)
Teknik Pemrograman Terstruktur I, Universitas Gunadarma (2006 - Now)
Teknik Pemrograman Terstruktur II, Universitas Gunadarma (2006 - Now)
89