Kamis, 30 September 2010

CITRA RGB to GRAY


CITRA WARNA MENJADI GRAYSCALE (ABU-ABU)

Dengan Visual Basic 6.0

    Pengolahan Citra


 




 













Buat Form seperti dia atas (Form1.frm)

    Masukkan :     
PictureBox              (3x)    (dengan Name : Picture1, Picture2,Picture3)             
CommandButton     (2x)    (dengan Name : CommandButton1, CommandButton2)                       
Commondialog        (1x)    (dengan Name : CommonDialog1 ) 
[ditambahkan dari Components : "Microsoft Common Dialog Control 6.0" ]  
(Tulisan "rata-rata" dan "Optimal" tidak perlu dimasukkan)


 

BUKA Jendela "View Code"

Masukkan Code berikut :


 

Private Sub Command1_Click() 'Load/browse picture
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub

 

Private Sub Command2_Click() 'merubah RGB -> GRAYSCALE
Dim i As Integer, j As Integer
Dim r As Integer, g As Integer, b As Integer
Dim warna As Long, x As Integer, y As Integer

 
Me.MousePointer = vbHourglass

 
For i = 1 To Picture1.Width Step 15
For j = 1 To Picture1.Height Step 15
warna = Picture1.Point(i, j)
r = warna And RGB(255, 0, 0)
g = Int((warna And RGB(0, 255, 0)) / 256)
b = Int(Int((warna And RGB(0, 0, 255)) / 256) / 256)
x = Int((r + g + b) / 3)
y = 0.42 * r + 0.32 * g + 0.28 * b
Picture2.PSet (i, j), RGB(x, x, x)
Picture3.PSet (i, j), RGB(y, y, y)
Next j
Next i
Me.MousePointer = vbNormal
End Sub

 

SELESAI AND START RUN!!

KLIK "OPEN FILE GAMBAR" –pilih gambarnya- Klik "RGB TO GRAY" =


 

THIS IS IT!




 
















                        Ala Chief SUPERYAN QUEEN

2 komentar:

  1. ahhahahaha apa pulank..

    mau tombol SAVE

    Private Sub Command3_Click() 'SAVE picture
    CommonDialog1.ShowSAVE
    Picture1.Picture = SAVEPicture(CommonDialog1.FileName)
    End Sub

    kada tau mau apa kada....ahahaha

    BalasHapus