HALAMAN PENGESAHAN
( ENHANCEMENT 3 )
Oleh :
Disetujui oleh :
1
2
DAFTAR ISI
HALAMAN SAMPUL
HALAMAN PENGESAHAN..................................................................................................i
DAFTAR ISI...........................................................................................................................ii
DAFTAR GAMBAR.............................................................................................................iii
DAFTAR TABEL..................................................................................................................iiv
6.9 Analisa...................................................................................................................33
6.10 Kesimpulan............................................................................................................65
DAFTAR PUSTAKA............................................................................................................66
DAFTAR GAMBAR
2
3
DAFTAR TABEL
4
5
5
6
PRAKTIKUM6
( ENHANCEMENT 3)
Inversi citra adalah proses negatif pada citra, misalkan pada photo, dimana
setiap nilai citra dibalik dengan acuan threshold yang diberikan. Proses ini banyak
digunakan pada citra-citra medis seperti USG dan X-Ray. Untuk citra dengan derajat
keabuan 256, proses inversi citra didefinisikan dengan:
xn=255x
Dimana G adalah citra hasil, F citra asal, c adalah konstanta yang dipasang sebagai efek
perubahan kontras
2
Transformasi Power Law ada dua yaitu nth power dan nth root power
Dimana G adalah citra hasil, F adalah citra asal, c dan y adalah konstanta positif
Kontras dalam suatu citra menyatakan distribusi warna terang dan warna gelap.
Suatu citra berskala keabuan dikatakan memiliki kontras rendah apabila distribusi warna
cenderung pada jangkauan aras keabuan yang sempit. Sebaliknya, citra mempunyai
kontras tinggi apabila jangkauan aras keabuan lebih terdistribusi secara melebar.Kontras
dapat diukur berdasarkan perbedaan antara nilai intensitas tertinggi dan nilai intensitas
terendah yang menyusun piksel-piksel dalam citra.
1. Tujuan praktikum :
Mahasiswa dapat membuat program untuk proses Invers citra
Mahasiswa dapat membuat program untuk memperjelas Kontras citra
2. Cara mengubah citra menjadi invers
3
Contoh :Jika di ketahui suatu titik pixel dengan nilai Intensitas awal 20 dengan
menggunakan persamaan diatas dapat di hitung S = (256-1) - 20, maka akan di
peroleh nilai Inversnya yaitu 235.
1. Membuatlah project baru dengan form dan buat seperti berikut ini :
Picture4.BackColor = vbWhite
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 = (R + g + b) / 3
Dim xb = 255h1(256)
h(256), -x As Integer
For i Picture1.PSet
= 1 To 256 (i, j), RGB(x, x, x)
h(i)Picture2.PSet
= 0: h1(i) = 0(i, j), RGB(xb, xb, xb)
Next
Next i j
Next i 1 To Picture1.Width Step 15
For i =
For j = 1 To Picture1.Height Step 15
warna = Picture1.Point(i, j)
3. Pada tombol
R = warna Histogram
And RGB(255,mengisikansource
0, 0) program :
g = Int((warna And RGB(0, 255, 0)) / 256)
b = Int(Int((warna And RGB(0, 0, 255)) / 256) / 256)
x = (R + g + b) / 3
h(x + 1) = h(x + 1) + 1
Next j
Next i
For i = 1 To Picture2.Width Step 15
For j = 1 To Picture2.Height Step 15
warna2 = Picture2.Point(i, j)
R = warna2 And RGB(255, 0, 0)
g = Int((warna2 And RGB(0, 255, 0)) / 256)
b = Int(Int((warna2 And RGB(0, 0, 255)) / 256) / 256)
x = (R + g + b) / 3
h1(x + 1) = h1(x + 1) + 1
For i = 1 To 256
xp = 15 * (i - 1) + 1
Picture3.Line (xp, Picture3.Height - h(i))-(xp, Picture3.Height), RGB(255, 0, 0)
Picture4.Line (xp, Picture4.Height - h1(i))-(xp, Picture4.Height), RGB(255, 0,
255)
5
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
Picture1.PaintPicture Picture1.Picture, _
0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, _
0, 0, _
Picture1.Picture.Width / 26.46, _
Picture1.Picture.Height / 26.46
Picture1.Picture = Picture1.Image
1. Membuatlah project baru dengan form dan buat seperti berikut ini :
Public
Dim x, h1(0 To 255) AsInteger
xb AsInteger
Public h2(0 To
Dim gambar1 255)Bitmap(PictureBox1.Image)
AsNew AsInteger
Dim hmaxg1
Dim gambar2 AsNew Bitmap(PictureBox2.Image)
AsInteger
Dim hmaxg2hmaxg1 = 0
AsInteger
hmaxg2 = 0
For i AsInteger = 0 To 255
h1(i) = 0
h2(i) = 0
4. Pada
NextButton1 atau pada tombol Invers mengisikansource program :
For i AsInteger = 0 To PictureBox1.Width - 1
For j AsInteger = 0 To PictureBox1.Height - 1
Dim r AsInteger = gambar1.GetPixel(i, j).R
Dim g AsInteger = gambar1.GetPixel(i, j).G
Dim b AsInteger = gambar1.GetPixel(i, j).B
x = (r + g + b) / 3
xb = 255 - x
If xb >= 255 Then
xb = 255
ElseIf xb <= 0 Then
xb = 0
EndIf
h1(x) = h1(x) + 1
h2(xb) = h2(xb) + 1
gambar1.SetPixel(i, j, Color.FromArgb(x, x,
x))
gambar2.SetPixel(i, j, Color.FromArgb(xb,
xb, xb))
Next j
Next i
PictureBox1.Image = gambar1
PictureBox2.Image = gambar2
For tinggi1 AsInteger = 0 To 255
If h1(tinggi1) > hmaxg1 Then
hmaxg1 = h1(tinggi1)
EndIf
Next
For tinggi2 AsInteger = 0 To 255
If h2(tinggi2) > hmaxg2 Then
hmaxg2 = h2(tinggi2)
EndIf
Next
For i = 0 To 255
Me.Chart1.Series("Series1").Points.AddXY(i, h1(i))
Next
For i = 0 To 255
Me.Chart2.Series("Series1").Points.AddXY(i, h2(i))
Next
8
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
Picture1.PaintPicture Picture1.Picture, _
0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, _
0, 0, _
Picture1.Picture.Width / 26.46, _
Picture1.Picture.Height / 26.46
Picture1.Picture = Picture1.Image
EndSub
14
Picture4.BackColor = vbWhite
bg = Val(HScroll1) / 10
For i = 1 To Picture1.Width Step 15
For j = 1 To Picture1.Height Step 15
warna = Picture1.Point(i, j)
R = warna
R = warna AndAnd RGB(255,
RGB(255, 0, 0)0, 0)
g = Int((warna And RGB(0,
g = Int((warna And RGB(0, 255, 255,0))0))/ 256)
/ 256)
b = Int(Int((warna And RGB(0, 0,
b = Int(Int((warna And RGB(0, 0, 255)) / 256) 255)) / 256)/ 256)
/ 256)
x =Program
x =List
(R +(R
g ++ b)
g +/Histogram
3b) / 3
xb = (bg * x)
h(x + 1) = h(x + 1) + 1
NextPicture1.PSet
j (i, j), RGB(x, x, x)
Dim Picture2.PSet
h(256), h1(256) (i, As Integer xb, xb)
j), RGB(xb,
Next i
ForNext
i = 1j To 256
For i = 1 To Picture2.Width Step 15
h(i) = 0: h1(i) = 0
Next
For j i= 1 To Picture2.Height Step 15
Next i
warna2 = Picture2.Point(i, j)
For i = 1 To Picture1.Width Step 15
R = warna2 And RGB(255, 0, 0)
For j = 1 To Picture1.Height Step 15
g = Int((warna2 And RGB(0, 255, 0)) / 256)
warna = Picture1.Point(i, j)
b = Int(Int((warna2 And RGB(0, 0, 255)) / 256) / 256)
x = (R + g + b) / 3
h1(x + 1) = h1(x + 1) + 1
Next j
Next i
For i = 1 To 256
xp = 15 * (i - 1) + 1
Picture3.Line (xp, Picture3.Height - h(i))-(xp, Picture3.Height),
RGB(0, 0, 0)
Picture4.Line (xp, Picture4.Height - h1(i))-(xp, Picture4.Height),
RGB(0, 0, 0)
Next i
23
PublicClass Form1
Public h1(0 To 255) AsInteger
Public h2(0 To 255) AsInteger
Dim hmaxg1 AsInteger
Dim hmaxg2 AsInteger
Gambar 6.32 Invers sender
PrivateSub Button1_Click(ByVal dengan nilai 231
As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
Dim bmp AsNew Bitmap(PictureBox1.Image)
Dim c As Color
Dim r, g, b AsString
Dim data, warna() AsString
Dim h(360), s(100), v(255) AsInteger
Dim h1, s1, v1 AsInteger
For i AsInteger = 0 To PictureBox1.Width - 1
For j AsInteger = 0 To PictureBox1.Height - 1
c = bmp.GetPixel(i, j)
r = CStr(c.R)
g = CStr(c.G)
b = CStr(c.B)
data = rgb2hsv(r + "," + g + "," + b)
warna = data.Split(",")
h1 = CInt(warna(0))
s1 = Math.Floor(warna(1) * 100)
v1 = Math.Floor(warna(2) * 255)
h(h1) = h(h1) + 1
Gambar
s(s1) =6.33 Invers
s(s1) + dengan
1 nilai 46
v(v1) = v(v1) + 1
Next
Next
6.8.4.
DimHSV dan Ycbcr = Chart1.ClientSize.Height
ht AsInteger
6.8.5.
DimProgram HSV
xt AsInteger
For x = 0 To 360
xt = Chart1.ClientSize.Width * x / 360
Me.Chart1.Series("Series1").Points.AddXY(xt, h(x) / 8)
Next
For x = 0 To 100
xt = Chart1.ClientSize.Width * x / 100
Me.Chart2.Series("Series1").Points.AddXY(xt, s(x) / 8)
Next
For x = 0 To 255
xt = Chart1.ClientSize.Width * x / 255
Me.Chart3.Series("Series1").Points.AddXY(xt, v(x) / 8)
Next
EndSub
EndClass
28
6.8.6. Sharpness
Public h1(0 To 255) AsInteger
Public h2(0 To 255) AsInteger
Public h3(0 To 255) AsInteger
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Chart1.Series("Series1").Points.Clear()
Chart2.Series("Series1").Points.Clear()
Chart3.Series("Series1").Points.Clear()
Dim gambar1 AsNew Bitmap(PictureBox1.Image)
Dim gambar2 AsNew Bitmap(PictureBox2.Image)
Dim c() AsInteger
For i AsInteger = 0 To 255
h1(i) = 0
h2(i) = 0
h3(i) = 0
Next
Dim nilai AsInteger = TrackBar1.Value
PublicFunction
For i AsInteger sharp(ByVal bmp As Bitmap,- ByVal
= 0 To PictureBox1.Width 1 i AsInteger,
ByVal
For j AsInteger,
j AsInteger = 0 ByVal val_sharp AsInteger)
To PictureBox1.Height - 1 AsInteger()
Dim r, r1, g, g1, c =b,sharp(gambar1,
b1 AsInteger i, j, nilai)
r1 = bmp.GetPixel(i - 1, j - 1).R
gambar2.SetPixel(i, j, Color.FromArgb(c(0),
g1 =
c(1), c(2))) bmp.GetPixel(i - 1, j - 1).G
b1 = bmp.GetPixel(i
h1(c(0)) -+=1,1 j - 1).B
r = bmp.GetPixel(i,
h2(c(1)) j).R
+= 1
g =Module sharp
bmp.GetPixel(i,
h2(c(2)) j).G
+= 1
b = bmp.GetPixel(i, j).B
Next
Next
Dim clr(2) AsInteger
PitcureBox2.Image
clr(0) = truncate(r + =val_sharp
gambar2 * (r - r1) / 100)
For iclr(1)
= 0 To= 255
truncate(g + val_sharp * (g - g1) / 100)
Me.Chart1.Series("Series1").Points.AddXY(i,
clr(2) = truncate(b + val_sharp * (b - b1) h1(i))
/ 100)
Me.Chart2.Series("Series1").Points.AddXY(i, h2(i))
Me.Chart3.Series("Series1").Points.AddXY(i,
Return clr h3(i))
Next
EndFunction
29
6.8 Analisa
1. Invers VB.6
tipe data integer. Kemudian dengan kondisi And dimana warna dari gambar
picture1 dicocokan dengan warna RGB untuk warna green serta kode dari
warna green dibagi dengan 256.
xb = 255 xrumus untuk mencari invers dari nilai 255 dikurangi nilai x.
Picture2.PSet (i, j), RGB(xb, xb, xb)Memberikan nilai invers pada setiap
pixel rgb.
h(i) = 0: h1(i) = 0
Next i
2. Invers VB.Net
Public h1(0 To 255) As Integervariable public dengan nama h1 sebagai
Integer.
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImageuntuk
membuat gambar fit di picturebox dengan kondisi Strech mengikuti picture
box.
3. Kontras VB.6
xp = 15 * (i - 1) + 1
4. Kontras VB.Net
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImageuntuk
membuat gambar fit di picturebox dengan kondisi Strech.
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImageuntuk
membuat gambar fit di picturebox dengan kondisi Strech.
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImageuntuk
membuat gambar fit di picturebox dengan kondisi Strech.
8. HSV
9. Sharpness
Me.Chart1.Series("Series1").Points.AddXY(i, h1(i))cetak tampilan chart1.
1. Invers
37
2. Kontras
Gambar6.38Kontras VB.Net
Gambar 6.42Invers 46
41
6.9 Kesimpulan
Invers adalah proses pengubahan citra gambar menjadi citra gambar positif layaknya
klise foto. histogram yang dihasilkan akan cenderung ke kiri atau kebalikan dari
histogram asli sebelum gambar tersebut diinvers
42
DAFTAR PUSTAKA
Nana, 2011,Enhancement
Citra(http://nana.lecturer.pens.ac.id/index_files/materi/2011/Citra/Enhance
ment Citra.pdf) diakses pada 4Mei 2017