Download docx - Perbaikan Kualitas Citra

Transcript
Page 1: Perbaikan Kualitas Citra

Inggih Permana

10751000018

1. Peregangan Kontras (Contrast Stretching)

Setelah mencoba rumus yang ada di diktat yaitu S = ((R – Rmax)/(Rmin – Rmax))*255, hasil yang didapat seperti invert, berikut screen shoot nya:

Tetapi setelah mencari referensi lain dan mendapatkan rumus S = ((R – Rmin)/(Rmax – Rmin))*255, hasil yang didapat sebagai berikut:

Page 2: Perbaikan Kualitas Citra

Berikut source code nya

Sub PerengganganKontras(pfIndex As Integer) Dim pX As Long, pY As Long Dim x As Long, y As Long Dim MaxRed, MaxGreen, MaxBlue As Long Dim MinRed, MinGreen, MinBlue As Long Dim colorval As Long Dim red As Long, green As Long, blue As Long Dim red2 As Long, green2 As Long, blue2 As Long MaxRed = 0 MaxGreen = 0 MaxBlue = 0 MinRed = 255 MinGreen = 255 MinBlue = 255 pX = mdiImgProcess.ActiveForm.pcbPicture.ScaleWidth - 1 pY = mdiImgProcess.ActiveForm.pcbPicture.ScaleHeight - 1 For x = 0 To pX For y = 0 To pY colorval = GetPixel(hDCSour(pfIndex), x, y) red = GetRed(colorval) green = GetGreen(colorval) blue = GetBlue(colorval) If MaxRed < red Then MaxRed = red If MaxGreen < green Then MaxGreen = green If MaxBlue < blue Then MaxBlue = blue If MinRed > red Then MinRed = red If MinGreen > green Then MinGreen = green If MinBlue > blue Then MinBlue = blue Next y Next x For x = 0 To pX For y = 0 To pY colorval = GetPixel(hDCSour(pfIndex), x, y) red = GetRed(colorval) green = GetGreen(colorval) blue = GetBlue(colorval) red2 = ((red - MinRed) / (MaxRed - MinRed)) * 255 green2 = ((green - MinGreen) / (MaxGreen - MinGreen)) * 255 blue2 = ((blue - MinBlue) / (MaxBlue - MinBlue)) * 255 If red2 >= 255 Then red2 = 255 If green2 >= 255 Then green2 = 255 If blue2 >= 255 Then blue2 = 255 If red2 <= 0 Then red2 = 0 If green2 <= 0 Then green2 = 0 If blue2 <= 0 Then blue2 = 0

Page 3: Perbaikan Kualitas Citra

SetPixel hDCDest(pfIndex), x, y, RGB(red2, green2, blue2) Next y If (x Mod (pX / 20)) = 0 Then frmBright.ProgressBar.Value = x / pX * 100 Next x BitBlt mdiImgProcess.ActiveForm.pcbPicture.hdc, 0, 0, mdiImgProcess.ActiveForm.pcbPicture.ScaleWidth, mdiImgProcess.ActiveForm.pcbPicture.ScaleHeight, hDCDest(pfIndex), 0, 0, vbSrcCopy mdiImgProcess.ActiveForm.pcbPicture.Refresh If frmBright.Preview = False Then BitBlt hDCSour(pfIndex), 0, 0, mdiImgProcess.ActiveForm.pcbPicture.ScaleWidth, mdiImgProcess.ActiveForm.pcbPicture.ScaleHeight, mdiImgProcess.ActiveForm.pcbPicture.hdc, 0, 0, vbSrcCopyEnd Sub

2. Penajaman Tepi (Edge Sharping)

Dalam tugas ini saya memakai penapis lolos-tinggi sebagai berikut :

-1 -1 -1

-1 9 -1

-1 -1 -1

Hasilnya sebagai berikut :

Page 4: Perbaikan Kualitas Citra

Berikut source code nya:

Sub PenajamanTp(pfIndex As Integer) Dim pX As Long, pY As Long Dim x As Long, y As Long Dim colorval As Long Dim red As Long, green As Long, blue As Long Dim red2 As Long, green2 As Long, blue2 As Long 'Mask Dim mask(3, 3) As Integer mask(0, 0) = -1 mask(0, 1) = -1 mask(0, 2) = -1 mask(1, 0) = -1 mask(1, 1) = 9 mask(1, 2) = -1 mask(2, 0) = -1 mask(2, 1) = -1 mask(2, 2) = -1 pX = mdiImgProcess.ActiveForm.pcbPicture.ScaleWidth - 1 pY = mdiImgProcess.ActiveForm.pcbPicture.ScaleHeight - 1

For x = 0 To pX For y = 0 To pY colorval = GetPixel(hDCSour(pfIndex), x, y) red = GetRed(colorval) green = GetGreen(colorval) blue = GetBlue(colorval) red2 = GetRed(GetPixel(hDCSour(pfIndex), x - 1, y - 1)) * mask(0, 0) + _ GetRed(GetPixel(hDCSour(pfIndex), x - 1, y + 1)) * mask(0, 1) + _ GetRed(GetPixel(hDCSour(pfIndex), x - 1, y)) * mask(0, 2) + _ GetRed(GetPixel(hDCSour(pfIndex), x, y - 1)) * mask(1, 0) + _ GetRed(GetPixel(hDCSour(pfIndex), x, y)) * mask(1, 1) + _ GetRed(GetPixel(hDCSour(pfIndex), x, y + 1)) * mask(1, 2) + _ GetRed(GetPixel(hDCSour(pfIndex), x + 1, y - 1)) * mask(2, 0) + _ GetRed(GetPixel(hDCSour(pfIndex), x + 1, y)) * mask(2, 1) + _ GetRed(GetPixel(hDCSour(pfIndex), x + 1, y + 1)) * mask(2, 2) green2 = GetGreen(GetPixel(hDCSour(pfIndex), x - 1, y - 1)) * mask(0, 0) + _ GetGreen(GetPixel(hDCSour(pfIndex), x - 1, y + 1)) * mask(0, 1) + _ GetGreen(GetPixel(hDCSour(pfIndex), x - 1, y)) * mask(0, 2) + _ GetGreen(GetPixel(hDCSour(pfIndex), x, y - 1)) * mask(1, 0) + _ GetGreen(GetPixel(hDCSour(pfIndex), x, y)) * mask(1, 1) + _ GetGreen(GetPixel(hDCSour(pfIndex), x, y + 1)) * mask(1, 2) + _ GetGreen(GetPixel(hDCSour(pfIndex), x + 1, y - 1)) * mask(2, 0) + _ GetGreen(GetPixel(hDCSour(pfIndex), x + 1, y)) * mask(2, 1) + _ GetGreen(GetPixel(hDCSour(pfIndex), x + 1, y + 1)) * mask(2, 2)

blue2 = GetBlue(GetPixel(hDCSour(pfIndex), x - 1, y - 1)) * mask(0, 0) + _ GetBlue(GetPixel(hDCSour(pfIndex), x - 1, y + 1)) * mask(0, 1) + _ GetBlue(GetPixel(hDCSour(pfIndex), x - 1, y)) * mask(0, 2) + _ GetBlue(GetPixel(hDCSour(pfIndex), x, y - 1)) * mask(1, 0) + _

Page 5: Perbaikan Kualitas Citra

GetBlue(GetPixel(hDCSour(pfIndex), x, y)) * mask(1, 1) + _ GetBlue(GetPixel(hDCSour(pfIndex), x, y + 1)) * mask(1, 2) + _ GetBlue(GetPixel(hDCSour(pfIndex), x + 1, y - 1)) * mask(2, 0) + _ GetBlue(GetPixel(hDCSour(pfIndex), x + 1, y)) * mask(2, 1) + _ GetBlue(GetPixel(hDCSour(pfIndex), x + 1, y + 1)) * mask(2, 2) If red2 < 0 Then red2 = 0 End If If red2 > 255 Then red2 = 255 End If If green2 < 0 Then green2 = 0 End If If green2 > 255 Then green2 = 255 End If If blue2 < 0 Then blue2 = 0 End If If blue2 > 255 Then blue2 = 255 End If SetPixel hDCDest(pfIndex), x, y, RGB(red2, green2, blue2) Next y If (x Mod (pX / 20)) = 0 Then frmProgress.ProgressBar.Value = x / pX * 100 Next x BitBlt mdiImgProcess.ActiveForm.pcbPicture.hdc, 0, 0, mdiImgProcess.ActiveForm.pcbPicture.ScaleWidth, mdiImgProcess.ActiveForm.pcbPicture.ScaleHeight, hDCDest(pfIndex), 0, 0, vbSrcCopy mdiImgProcess.ActiveForm.pcbPicture.Refresh BitBlt hDCSour(pfIndex), 0, 0, mdiImgProcess.ActiveForm.pcbPicture.ScaleWidth, mdiImgProcess.ActiveForm.pcbPicture.ScaleHeight, mdiImgProcess.ActiveForm.pcbPicture.hdc, 0, 0, vbSrcCopy Unload frmProgressEnd Sub


Recommended