Image Processing Menggunakan Visual Basic
1.1
Pixel Bagian terkecil dari suatu citra digital adalah pixel. Setiap pixel terdiri dari tiga
warna yaitu RED,GREEN dan BLUE (RGB). Warna pixel untuk jenis warna 8 bit disimpan dalam suatu gabungan warna
Sehingga didapatkan intensitas masing-masing warna akan berkisar diantara 0 dan 255. Gabungan ketiga warna dengan masing-masing intensitas yang berbeda akan menghasilkan warna yang cukup banyak dengan jumlah warna sebanyak 256*256*256 atau =16777216. Warna R G dan B dari warna gabungan W didapat dengan menggunakan
sub fungsi pada program 1.1
Program 1.1 Sub Fungsi Konversi Warna ke RGB
Sub GetWarna(w, r As Integer, g As Integer, b As Integer)
Dim
wd wd = w
r = wd And 255
wd = Fix(wd / 256)
g = wd And 255
wd = Fix(wd / 256)
b = wd And 255
End Sub
Object Properti Isi
Picturebox Name PicW
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicR
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicG
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicB
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Command Button Name CmdProses
Caption Proses
c. Program
Sub GetWarna(w, r As Integer, g As Integer, b As Integer)
Dim wd
wd = w
r = wd And 255
wd = Fix(wd / 256)
g = wd And 255
wd = Fix(wd / 256)
b = wd And 255
End Sub
Private Sub CmdProses_Click()
Dim r As Integer, g As Integer, b As Integer
For i = 0 To PicW.ScaleWidth
For j = 0 To PicW.ScaleHeight
w = PicW.Point(i, j)
GetWarna w, r, g, b
PicR.PSet (i, j), RGB(r, 0, 0)
PicG.PSet (i, j), RGB(0, g, 0)
PicB.PSet (i, j), RGB(0, 0, b)
Next
Next
end sub
---Histogram------
b. Object Property
Object Properti Isi
Picturebox Name PicW
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicHR
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicHG
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicHB
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicHGr
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Command Button Name CmdProses
Caption Proses
c. Program
Dim hr(0 To 255) As Integer '' Histogram Warna merah
Dim hg(0 To 255) As Integer ''Histogram Warna Hijau
Dim hb(0 To 255) As Integer ''Histogram Warna Biru
Dim hgr(0 To 255) As Integer ''Histogram Warna Grey
Sub GetWarna(w, r As Integer, g As Integer, b As Integer)
Dim wd
wd = w
r = wd And 255
wd = Fix(wd / 256)
g = wd And 255
wd = Fix(wd / 256)
b = wd And 255
End Sub
Sub GetHistogram(
Pic As PictureBox, hr() As Integer, hg() As Integer, hb() As Integer, hgr() As Integer)
Dim r As Integer, g As Integer, b As Integer
lebar = pic.ScaleWidth
tinggi = pic.ScaleHeight
For i = 0 To lebar
hr(i) = 0
hg(i) = 0
hb(i) = 0
hgr(i) = 0
Next
For i = 0 To lebar
For j = 0 To tinggi
w = pic.Point(i, j)
GetWarna w, r, g, b
hr(r) = hr(r) + 1
hg(g) = hg(g) + 1
hb(b) = hb(b) + 1
gr = Fix((r + g + b) / 3)
hgr(gr) = hgr(gr) + 1
Next
Next
End Sub
Sub DrawHistogram(pic As PictureBox, h() As Integer)
''Sub Program Untuk Menggambar Histogram
pic.DrawWidth = 2
pic.Cls
lebar = pic.ScaleWidth
tinggi = pic.ScaleHeight
st = lebar / 256
wmax = 0
''Normalisasi Ketinggian
For i = 0 To 255
If h(i) > wmax Then wmax = h(i)
Next
For i = 0 To 255
x = i * st
y = tinggi - h(i) / wmax * tinggi
pic.Line (x, tinggi)-(x, y), RGB(0, 0, 0)
Next
pic.Refresh
End Sub
Private Sub CmdProses_Click()
GetHistogram PicW, hr(), hg(), hb(), hgr
DrawHistogram PicHr, hr()
DrawHistogram PicHg, hg()
DrawHistogram PicHb, hb()
DrawHistogram PicHgr, hgr()
End Sub
------------
1.3 Brigthness (Pencerahan Citra)
Salah satu pemmanfaat histogram adalah brithhnesahan citra. Untuk melakukan pencerahaan citra dilakukan dengan cara menggeser histogram kearah kanan dengan cara menambah level warna dengan suatu konstanta.
RBaru = RLama+ Level
GBaru = GLama+ level
BBaru = BLama+ level
b. Object Property
Object Properti Isi
Picturebox Name PicW
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Picturebox Name PicO
AutoRedraw True
AutoSize True
Scale Mode 3-Pixel
Command Button Name CmdProses
Caption Proses
Sub GetWarna(w, R As Integer, G As Integer, b As Integer)
Dim wd
wd = w
R = wd And 255
wd = Fix(wd / 256)
G = wd And 255
wd = Fix(wd / 256)
b = wd And 255
End Sub
Sub BrightNess(Pic As PictureBox, PicOut As PictureBox, Level As Integer)
Dim R As Integer, G As Integer, b As Integer
lebar = Pic.ScaleWidth
Tinggi = Pic.ScaleHeight
For i = 0 To lebar
For j = 0 To Tinggi
w = Pic.Point(i, j)
GetWarna w, R, G, b
R = R + Level
G = G + Level
b = b + Level
If R > 255 Then R = 255
If R 255 Then G = 255
If G 255 Then b = 255
If b < 0 Then b = 0
PicO.PSet (i, j), RGB(R, G, b)
Next
Next
End Sub
Private Sub CmdProses_Click()
BrightNess PicW, PicO, 100
PicW.Refresh
End Sub
Resensi lain tentang www.shvoong.com