LAPORAN PRAKTIKUM PENGOLAHAN CITRA DIGITAL PERBAIKAN CITRA ( ENHANCEMENT 2 ) Oleh : PROGRAM STUDI TEKNIK INFORMATIKA JURUSAN TEKNOLOGI INFORMSASI DAN KOMPUTER TAHUN 2015 Nama : Hadi Mulya NIM : 1257301055 Kelas : G3.1 DosenPembimbing : Sila Abdulla Syakri,S.T.,M.T.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
LAPORAN PRAKTIKUM
PENGOLAHAN CITRA DIGITAL
PERBAIKAN CITRA ( ENHANCEMENT 2 )
Oleh :
PROGRAM STUDI TEKNIK INFORMATIKA
JURUSAN TEKNOLOGI INFORMSASI DAN KOMPUTER
TAHUN 2015
Nama : Hadi Mulya
NIM : 1257301055
Kelas : G3.1
DosenPembimbing : Sila Abdulla Syakri,S.T.,M.T.
i
LEMBAR PENGESAHAN
No. Praktikum : 04/TI/PCD/G3.1/2015
Judul : Perbaikan Citra (Enhancement 2)
Nama : Hadi Mulya
NIM : 1257301055
Kelas : G-3
Jurusan : Teknik Elektro
Prodi : Teknik Informatika
Tanggal praktikum : 31 Maret 2015
Tanggal penyerahan : 7 April 2015
Nilai :
Buketrata, 7 April 2015
Dosen Pembimbing,
Sila Abdulla Syakri,S.T.,M.T.
ii
DAFTAR ISI
LEMBAR PENGESAHAN ...................................................................................... i
DAFTAR ISI ............................................................................................................ii
DAFTAR GAMBAR ................................................. Error! Bookmark not defined.
DAFTAR TABEL ................................................................................................... iv
1. Mengubah program dengan konstras positif dan negative dengan hscroll1
dengan min -127 dan max 127 . Serta membuat histogram. Menjelaskan
antara kondisi negatif dan positif
Listing program pada VB.net
Public Class Form1 Private histogramValues(256) As Integer Private histogramValuesBg(256) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, j, k, xb As Integer Dim r, g, b, x As Double Dim gambar = New Bitmap(PictureBox1.Image) Dim gambar2 As Bitmap = New Bitmap(PictureBox1.Image) k = HScrollBar1.Value For i = gambar.Width - 1 To 0 Step -1 For j = gambar.Height - 1 To 0 Step -1 r = gambar.GetPixel(i, j).R g = gambar.GetPixel(i, j).G b = gambar.GetPixel(i, j).B x = (r + g + b) / 3 xb = x + k If (xb > 255) Then xb = 255 ElseIf (xb < 0) Then xb = 0 End If 'If k < 255 Then k = 255 gambar.SetPixel(i, j, Color.FromArgb(x, x, x)) gambar2.SetPixel(i, j, Color.FromArgb(xb, xb, xb)) Next PictureBox1.Refresh() PictureBox2.Refresh() PictureBox1.Image = gambar PictureBox2.Image = gambar2 Next End Sub Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
6
TextBox1.Text = HScrollBar1.Value End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ReDim histogramValues(256) ReDim histogramValuesBg(256) Dim bmp As New Bitmap(PictureBox1.Image, PictureBox1.Width, PictureBox1.Height) PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle) PictureBox1.Image = bmp For y As Integer = 0 To bmp.Height - 1 For x As Integer = 0 To bmp.Width - 1 Dim r As Integer = bmp.GetPixel(x, y).R Dim g As Integer = bmp.GetPixel(x, y).G Dim b As Integer = bmp.GetPixel(x, y).B Dim Rumus As Single = ((r + g + b) / 3) histogramValues(Rumus + 1) = histogramValues(Rumus + 1) + 1 bmp.SetPixel(x, y, Color.FromArgb(Rumus, Rumus, Rumus)) Next Next PictureBox3.Invalidate() Dim bmpBg As New Bitmap(PictureBox2.Image, PictureBox2.Width, PictureBox2.Height) PictureBox2.DrawToBitmap(bmpBg, PictureBox2.ClientRectangle) PictureBox2.Image = bmpBg For y As Integer = 0 To bmpBg.Height - 1 For x As Integer = 0 To bmpBg.Width - 1 Dim r As Integer = bmpBg.GetPixel(x, y).R Dim g As Integer = bmpBg.GetPixel(x, y).G Dim b As Integer = bmpBg.GetPixel(x, y).B Dim Rumus As Single = ((r + g + b) / 3) histogramValuesBg(Rumus + 1) = histogramValuesBg(Rumus + 1) + 1 bmpBg.SetPixel(x, y, Color.FromArgb(Rumus, Rumus, Rumus)) Next Next PictureBox4.Invalidate() End Sub Private Sub PictureBox3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox3.Paint If histogramValues.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox3.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValues(i) / histogramValues.Max) Dim x As Integer = (PictureBox3.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Black, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub
7
Private Sub PictureBox4_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox4.Paint If histogramValuesBg.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox4.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesBg(i) / histogramValuesBg.Max) Dim x As Integer = (PictureBox4.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Black, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub End Class
Hasil Program
- Kondisi negatif
Gambar 5.3 Form untuk Brightness untuk kondisi negatif
8
- Kondisi positif
Gambar 5.4 Form untuk Brightness kondisi positif
Jika pada kondisi negative, proses brightness akan menghasilkan citra yang
berwarna abu-abu / cenderung hitam dan hasil histogram akan dipotong pada
bagian akhirnya. Sebaliknya, pada citra positif yang menggunakan proses
brightness akan menghasilkan citra yang samar-samar / cenderung berwarna putih
dan hasil histogram akan dipotong pada bagian awalnya
2. Membuat program pada VB.net dengan tampilan histogram RGB
Listing Program
Public Class Form1 Private histogramValuesR(256) As Integer Private histogramValuesG(256) As Integer Private histogramValuesB(256) As Integer Private histogramValuesRBg(256) As Integer Private histogramValuesGBg(256) As Integer Private histogramValuesBBg(256) As Integer
9
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim i, j, k, xR, xG, xB As Integer Dim r, g, b As Double Dim gambar = New Bitmap(PictureBox1.Image) Dim gambar2 As Bitmap = New Bitmap(PictureBox1.Image) k = Int(HScrollBar1.Value) For i = gambar.Width - 1 To 0 Step -1 For j = gambar.Height - 1 To 0 Step -1 r = gambar.GetPixel(i, j).R g = gambar.GetPixel(i, j).G b = gambar.GetPixel(i, j).B ' x = (r + g + b) / 3 xR = r + k xG = g + k xB = b + k 'fungsi if sebagai kondisi nilai batas maximum dan minimum If (xR > 255) Or (xG > 255) Or (xB > 255) Then xR = 255 xG = 255 xB = 255 End If If (xR < 0) Or (xG < 0) Or (xB < 0) Then xR = 0 xG = 0 xB = 0 End If
Next PictureBox1.Refresh() PictureBox2.Refresh() PictureBox1.Image = gambar PictureBox2.Image = gambar2 Next End Sub Private Sub HScrollBar1_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles HScrollBar1.Scroll TextBox1.Text = HScrollBar1.Value End Sub Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click ReDim histogramValuesR(256) ReDim histogramValuesG(256) ReDim histogramValuesB(256) ReDim histogramValuesRBg(256) ReDim histogramValuesGBg(256) ReDim histogramValuesBBg(256) Dim bmp As New Bitmap(PictureBox1.Image, PictureBox1.Width, PictureBox1.Height) PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle) For y As Integer = 0 To bmp.Height - 1 For x As Integer = 0 To bmp.Width - 1 Dim r As Integer = bmp.GetPixel(x, y).R Dim g As Integer = bmp.GetPixel(x, y).G
10
Dim b As Integer = bmp.GetPixel(x, y).B histogramValuesR(r + 1) = histogramValuesR(r + 1) + 1 histogramValuesG(g + 1) = histogramValuesG(g + 1) + 1 histogramValuesB(b + 1) = histogramValuesB(b + 1) + 1 Next Next PictureBox3.Invalidate() PictureBox4.Invalidate() PictureBox5.Invalidate() Dim bmpBg As New Bitmap(PictureBox2.Image, PictureBox2.Width, PictureBox2.Height) PictureBox2.DrawToBitmap(bmpBg, PictureBox2.ClientRectangle) For y As Integer = 0 To bmpBg.Height - 1 For x As Integer = 0 To bmpBg.Width - 1 Dim r As Integer = bmpBg.GetPixel(x, y).R Dim g As Integer = bmpBg.GetPixel(x, y).G Dim b As Integer = bmpBg.GetPixel(x, y).B histogramValuesRBg(r + 1) = histogramValuesRBg(r + 1) + 1 histogramValuesGBg(g + 1) = histogramValuesGBg(g + 1) + 1 histogramValuesBBg(b + 1) = histogramValuesBBg(b + 1) + 1 Next Next PictureBox6.Invalidate() PictureBox7.Invalidate() PictureBox8.Invalidate() End Sub Private Sub PictureBox3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox3.Paint If histogramValuesR.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox3.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesR(i) / histogramValuesR.Max) Dim x As Integer = (PictureBox2.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Red, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub PictureBox4_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox4.Paint If histogramValuesG.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox4.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesG(i) / histogramValuesG.Max) Dim x As Integer = (PictureBox4.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Green, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub PictureBox5_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox5.Paint If histogramValuesB.Max <= 0 Then Exit Sub
11
Dim h As Integer = PictureBox5.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesB(i) / histogramValuesB.Max) Dim x As Integer = (PictureBox2.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Blue, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub PictureBox6_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox6.Paint If histogramValuesRBg.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox6.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesRBg(i) / histogramValuesRBg.Max) Dim x As Integer = (PictureBox6.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Red, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub PictureBox7_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox7.Paint If histogramValuesGBg.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox7.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesGBg(i) / histogramValuesGBg.Max) Dim x As Integer = (PictureBox7.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Green, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub PictureBox8_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox8.Paint If histogramValuesBBg.Max <= 0 Then Exit Sub Dim h As Integer = PictureBox8.ClientSize.Height For i As Integer = 0 To 255 Step 2 Dim barHeight As Integer = CInt(h * histogramValuesBBg(i) / histogramValuesBBg.Max) Dim x As Integer = (PictureBox8.ClientSize.Width * i) / 256 Using pn As New Pen(Brushes.Blue, 2) e.Graphics.DrawLine(pn, x, h - barHeight, x, h) End Using Next End Sub Private Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click Dim i, j, k, xR As Integer Dim r, g, b As Double Dim gambar = New Bitmap(PictureBox1.Image) Dim gambar2 As Bitmap = New Bitmap(PictureBox1.Image)
12
k = HScrollBar1.Value For i = gambar.Width - 1 To 0 Step -1 For j = gambar.Height - 1 To 0 Step -1 r = gambar.GetPixel(i, j).R g = gambar.GetPixel(i, j).G b = gambar.GetPixel(i, j).B ' x = (r + g + b) / 3 xR = r + k 'fungsi if sebagai kondisi nilai batas maximum dan minimum If (xR > 255) Then xR = 255 End If If (xR < 0) Then xR = 0 End If gambar.SetPixel(i, j, Color.FromArgb(r, g, b)) gambar2.SetPixel(i, j, Color.FromArgb(xR, g, b)) Next PictureBox1.Refresh() PictureBox2.Refresh() PictureBox1.Image = gambar PictureBox2.Image = gambar2 Next End Sub Private Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click Dim i, j, k, xG As Integer Dim r, g, b As Double Dim gambar = New Bitmap(PictureBox1.Image) Dim gambar2 As Bitmap = New Bitmap(PictureBox1.Image) k = HScrollBar1.Value For i = gambar.Width - 1 To 0 Step -1 For j = gambar.Height - 1 To 0 Step -1 r = gambar.GetPixel(i, j).R g = gambar.GetPixel(i, j).G b = gambar.GetPixel(i, j).B ' x = (r + g + b) / 3 xG = g + k 'fungsi if sebagai kondisi nilai batas maximum dan minimum If (xG > 255) Then xG = 255 End If If (xG < 0) Then xG = 0 End If gambar.SetPixel(i, j, Color.FromArgb(r, g, b)) gambar2.SetPixel(i, j, Color.FromArgb(r, xG, b)) Next PictureBox1.Refresh() PictureBox2.Refresh() PictureBox1.Image = gambar PictureBox2.Image = gambar2 Next
13
End Sub Private Sub Button6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button6.Click Dim i, j, k, xB As Integer Dim r, g, b As Double Dim gambar = New Bitmap(PictureBox1.Image) Dim gambar2 As Bitmap = New Bitmap(PictureBox1.Image) k = HScrollBar1.Value For i = gambar.Width - 1 To 0 Step -1 For j = gambar.Height - 1 To 0 Step -1 r = gambar.GetPixel(i, j).R g = gambar.GetPixel(i, j).G b = gambar.GetPixel(i, j).B ' x = (r + g + b) / 3 xB = b + k 'fungsi if sebagai kondisi nilai batas maximum dan minimum If (xB > 255) Then xB = 255 End If If (xB < 0) Then xB = 0 End If gambar.SetPixel(i, j, Color.FromArgb(r, g, b)) gambar2.SetPixel(i, j, Color.FromArgb(r, g, xB)) Next PictureBox1.Refresh() PictureBox2.Refresh() PictureBox1.Image = gambar PictureBox2.Image = gambar2 Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub End Class Hasil Program
14
Gambar 5.5 Hasil Brightness
Brightness warna merah
Gambar 5.6 Hasil Brightness Merah
Brightness warna hijau
Gambar 5.7 Hasil Brightness Hijau
15
Brightness warna biru
Gambar 5.8 Hasil Brightness Biru
5.6 ANALISA
16
5.8 KESIMPULAN
DAFTAR PUSTAKA
[1] Fadlisyah, S.Si. 2007.Computer Vision dan Pengolahan Citra. Yogyakarta :