# Fungsi Kelompok : yang dalam hal ini d adalah jumlah pixel yang terlibat dalam perhitungan rata-rata. Gambar 1 memperlihatkan dua buah skema

(1)

## Fungsi Kelompok :

(2)

(3)

### Algoritma berikut :

void PerataanCitra (citra image, citra imageresult, int N, int M)

/* Melembutkan citra image yang berukuran N x M dengan melakukan konvolusi citra image dengan penapis rerata yang berukuran 3 x 3. Hasil pelembutan disimpan di dalam image result. */

{ int I, j;

for (i=1; i<=N-1; i++) for (j=1; j<=M-1; j++) { imageresult [i][j] = image[i-1][j-1]+image[i-1][j]+image[i-1, j+1]+ image[i][j-1]+image[i][j]+image [I,j+1] + image[i+1][j-1]+image[i+1][j] + image[i+1,j+1]; imageresult[i][j] = imageresult[i][j]/9; } }

(4)

(5)

(6)

(7)

(8)

### Hasil Rancangan Tugas Kelompok :

(9)

Gambar 3. Form Hasil Efek Smooting Gambar 2. Form Histogram

(10)

## Listing Program

Form1

Private Sub cmdclose_Click() End

End Sub

Private Sub cmdhis_Click() Me.Hide Form2.Show For i = 0 To 255 X1 = Form2.Picture1.Width \ 256 + (i * (Form2.Picture1.Width \ 256)) Y1 = Form2.Picture1.Height Yr = Y1 - Frekuensi(0, i) Yg = Y1 - Frekuensi(1, i) Yb = Y1 - Frekuensi(2, i)

Form2.Picture1.Line (X1, Y1)-(X1, Yr) Form2.Picture2.Line (X1, Y1)-(X1, Yg) Form2.Picture3.Line (X1, Y1)-(X1, Yb) Next

End Sub

(11)

Private Sub cmdopen_Click() Dim i As Integer, j As Integer

Dim red As Integer, green As Integer, blue As Integer Dim Pixel As Long

Dim PictureName As String

CommonDialog1.InitDir = App.Path

CommonDialog1.Filter = "Image|*.BMP;*.GIF;*.JPG;*.DIB|All Files|*.*" CommonDialog1.Action = 1

PictureName = CommonDialog1.FileName If PictureName = "" Then Exit Sub

Picture1.Picture = LoadPicture(PictureName) Form1.Refresh

x = Picture1.ScaleWidth y = Picture1.ScaleHeight If x > 500 Or y > 500 Then

MsgBox "Image terlalu besar, Silahkan coba Image yang lebih kecil" x = 0

y = 0 Exit Sub End If

Form1.Width = Form1.ScaleX(Picture1.Width + 6, vbPixels, vbTwips) Form1.Height = Form1.ScaleY(Picture1.Height + 30, vbPixels, vbTwips) Form1.Refresh Form3.Show Form3.Refresh For i = 0 To y - 1 For j = 0 To x - 1 Pixel = Form1.Picture1.Point(j, i) red = Pixel& Mod 256

green = ((Pixel And &HFF00) / 256&) Mod 256& blue = (Pixel And &HFF0000) / 65536

ImagePixels(0, i, j) = red If red < 0 Then red = 0 If green < 0 Then green = 0 If blue < 0 Then blue = 0 ImagePixels(1, i, j) = green ImagePixels(2, i, j) = blue

Frekuensi(0, red) = Frekuensi(0, red) + 1 Frekuensi(1, green) = Frekuensi(1, green) + 1 Frekuensi(2, blue) = Frekuensi(2, blue) + 1 Next

Form3.ProgressBar1.Value = i * 100 / (y - 1) Next

Form3.Hide End Sub

Private Sub cmdsharp_Click() Dim i As Integer, j As Integer Const Dx As Integer = 1 Const Dy As Integer = 1

Dim red As Integer, green As Integer, blue As Integer Me.Hide

(12)

Form5.Show For i = 1 To y - 2 For j = 1 To x - 2

red = ImagePixels(0, i, j) + 0.5 * (ImagePixels(0, 1, j) _ - ImagePixels(0, i - Dx, j - Dy))

green = ImagePixels(1, i, j) + 0.5 * (ImagePixels(1, 1, j) _ - ImagePixels(1, i - Dx, j - Dy))

blue = ImagePixels(2, i, j) + 0.5 * (ImagePixels(2, 1, j) _ - ImagePixels(2, i - Dx, j - Dy))

If red > 255 Then red = 255 If red < 0 Then red = 0

If green > 255 Then green = 255 If green < 0 Then green = 0 If blue > 255 Then blue = 255 If blue < 0 Then blue = 0

Form5.Picture2.PSet (j, i), RGB(red, green, blue)

Form5.Picture1.PSet (j, i), RGB(ImagePixels(0, i, j), ImagePixels(1, i, j), ImagePixels(2, i, j))

Next

Form5.Picture2.Refresh Next

End Sub

Private Sub cmdsmoot_Click() Dim i As Integer, j As Integer

Dim red As Integer, green As Integer, blue As Integer Me.Hide

Form4.Show For i = 1 To y - 2 For j = 1 To x - 2

red = ImagePixels(0, i - 1, j - 1) + ImagePixels(0, i - 1, j) _ + ImagePixels(0, i - 1, j + 1) + ImagePixels(0, i, j - 1) _ + ImagePixels(0, i, j) + ImagePixels(0, i, j + 1) _

+ ImagePixels(0, i + 1, j - 1) + ImagePixels(0, i + 1, j) _ + ImagePixels(0, i + 1, j + 1)

green = ImagePixels(1, i - 1, j - 1) + ImagePixels(1, i - 1, j) _ + ImagePixels(1, i - 1, j + 1) + ImagePixels(1, i, j - 1) _ + ImagePixels(1, i, j) + ImagePixels(1, i, j + 1) _

+ ImagePixels(1, i + 1, j - 1) + ImagePixels(1, i + 1, j) _ + ImagePixels(1, i + 1, j + 1)

blue = ImagePixels(2, i - 1, j - 1) + ImagePixels(2, i - 1, j) _ + ImagePixels(2, i - 1, j + 1) + ImagePixels(2, i, j - 1) _ + ImagePixels(2, i, j) + ImagePixels(2, i, j + 1) _

+ ImagePixels(2, i + 1, j - 1) + ImagePixels(2, i + 1, j) _ + ImagePixels(2, i + 1, j + 1)

Form4.Picture2.PSet (j, i), RGB(red / 9, green / 9, blue / 9)

Form4.Picture1.PSet (j, i), RGB(ImagePixels(0, i, j), ImagePixels(1, i, j), ImagePixels(2, i, j))

Next

(13)

End Sub

Me.Top = (Screen.Height - Height) / 2 Me.Left = (Screen.Width - Width) / 2 End Sub

Form2

Me.Top = (Screen.Height - Height) / 2 Me.Left = (Screen.Width - Width) / 2 End Sub

Private Sub Form_Unload(Cancel As Integer) Form1.Show

End Sub

Form4

Me.Top = (Screen.Height - Height) / 2 Me.Left = (Screen.Width - Width) / 2 End Sub

Private Sub Form_Unload(Cancel As Integer) Form1.Show

End Sub

Form5

Me.Top = (Screen.Height - Height) / 2 Me.Left = (Screen.Width - Width) / 2 End Sub

Private Sub Form_Unload(Cancel As Integer) Form1.Show

End Sub

Module

Global ImagePixels(2, 800, 800) As Integer Global Frekuensi(2, 255) As Double Global x, y As Integer

(14)

## Fungsi Individu :

### Watermark

Gambar 5. Form Sebelum Diberi Efek Watermark

(15)

Listing Program Watermark :

Option Explicit

Private Function CombineColors(ByVal clr1 As OLE_COLOR, ByVal clr2 As OLE_COLOR, ByVal A As Byte) As OLE_COLOR

Dim r1 As Long Dim g1 As Long Dim b1 As Long Dim r2 As Long Dim g2 As Long Dim b2 As Long b1 = Int(clr1 / 65536) g1 = Int((clr1 - (65536 * b1)) / 256) r1 = clr1 - ((b1 * 65536) + (g1 * 256)) b2 = Int(clr2 / 65536) g2 = Int((clr2 - (65536 * b2)) / 256) r2 = clr2 - ((b2 * 65536) + (g2 * 256)) r1 = (A * r1 + (255 - A) * r2) \ 256 g1 = (A * g1 + (255 - A) * g2) \ 256 b1 = (A * b1 + (255 - A) * b2) \ 256 CombineColors = r1 + 256 * g1 + 65536 * b1 End Function

Private Sub Form_Load() Dim x As Integer Dim y As Integer picBackground.AutoRedraw = True picWatermark1.AutoRedraw = True picWatermark2.AutoRedraw = True picBackground.ScaleMode = vbPixels picWatermark1.ScaleMode = vbPixels picWatermark2.ScaleMode = vbPixels x = (picBackground.ScaleWidth - picWatermark1.ScaleWidth) \ 2 y = (picBackground.ScaleHeight - picWatermark1.ScaleHeight) \ 3 DrawWatermark picWatermark1, picBackground, x, y

y = 2 * (picBackground.ScaleHeight - picWatermark1.ScaleHeight) \ 3 DrawWatermark picWatermark2, picBackground, x, y

End Sub

Private Sub DrawWatermark(ByVal wm_pic As PictureBox, ByVal bg_pic As PictureBox, ByVal x As Integer, ByVal y As Integer)

Const ALPHA As Byte = 128 Dim transparent As OLE_COLOR Dim wm_clr As OLE_COLOR Dim bg_clr As OLE_COLOR Dim new_clr As OLE_COLOR Dim px As Integer

Dim py As Integer

(16)

wm_pic.ScaleMode = vbPixels bg_pic.ScaleMode = vbPixels For py = 0 To wm_pic.ScaleHeight - 1 For px = 0 To wm_pic.ScaleWidth - 1 wm_clr = wm_pic.Point(px, py) If wm_clr <> transparent Then bg_clr = bg_pic.Point(x + px, y + py)

new_clr = CombineColors(wm_clr, bg_clr, ALPHA) bg_pic.PSet (x + px, y + py), new_clr

End If Next px Next py End Sub

### Edge Detection

(17)

Listing Program Edge Detection : Option Explicit Dim Pixel Dim Pixel2 Dim Rred Dim Ggreen Dim Bblue Dim RR1 Dim GG1 Dim BB1 Dim RR2 Dim GG2 Dim BB2 Dim RR3 Dim GG3 Dim BB3 Dim Q As String Dim XXX As Integer Dim YYY As Integer Dim XX As Integer

(18)

Dim YY As Integer Dim RR As Integer Dim RG As Integer Dim RB As Integer

Private Sub GetRGB(ByVal Col As String) On Error Resume Next

Bblue = Col \ (256 ^ 2)

Ggreen = (Col - Bblue * 256 ^ 2) \ 256 Rred = (Col - Bblue * 256 ^ 2 - Ggreen * 256) End Sub

Private Sub Command21_Click() On Error Resume Next

Q = InputBox("Enter a value for find horizontal edges (higher value = brighter image)", "", "4")

If Q = "" Then Exit Sub

For YYY = 0 To Picture1.ScaleHeight - 1 For XXX = 0 To Picture1.ScaleWidth - 1

Pixel2 = GetPixel(Picture1.HDC, XXX + 2, YYY) Pixel = GetPixel(Picture1.HDC, XXX + 1, YYY) GetRGB Pixel RR1 = Rred GG1 = Ggreen BB1 = Bblue GetRGB Pixel2 RR2 = Rred GG2 = Ggreen BB2 = Bblue If RR1 = RR2 Then RR3 = 0 If RR1 > RR2 Then RR3 = RR1 - RR2 Else RR3 = RR2 - RR1 End If If GG1 = GG2 Then GG3 = 0 If GG1 > GG2 Then GG3 = GG1 - GG2 Else GG3 = GG2 - GG1 End If If BB1 = BB2 Then BB3 = 0 If BB1 > BB2 Then BB3 = BB1 - BB2 Else BB3 = BB2 - BB1 End If

SetPixelV Picture1.HDC, XXX, YYY, RGB(RR3 * Q, GG3 * Q, BB3 * Q) Next

Picture1.Refresh Next

(19)

End Sub

Private Sub Command22_Click() On Error Resume Next

Q = InputBox("Enter a value for find vertical edges (higher value = brighter image)", "", "4")

If Q = "" Then Exit Sub

For XXX = 0 To Picture1.ScaleWidth - 1 For YYY = 0 To Picture1.ScaleHeight - 1

Pixel2 = GetPixel(Picture1.HDC, XXX, YYY + 2) Pixel = GetPixel(Picture1.HDC, XXX, YYY + 1) GetRGB Pixel RR1 = Rred GG1 = Ggreen BB1 = Bblue GetRGB Pixel2 RR2 = Rred GG2 = Ggreen BB2 = Bblue If RR1 = RR2 Then RR3 = 0 If RR1 > RR2 Then RR3 = RR1 - RR2 Else RR3 = RR2 - RR1 End If If GG1 = GG2 Then GG3 = 0 If GG1 > GG2 Then GG3 = GG1 - GG2 Else GG3 = GG2 - GG1 End If If BB1 = BB2 Then BB3 = 0 If BB1 > BB2 Then BB3 = BB1 - BB2 Else BB3 = BB2 - BB1 End If

SetPixelV Picture1.HDC, XXX, YYY, RGB(RR3 * Q, GG3 * Q, BB3 * Q) Next

Picture1.Refresh Next

Picture1.Refresh End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

JB = 1 CurX = X CurY = Y End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

(20)

JB = 0 End Sub

Module

Declare Function GetPixel Lib "gdi32" (ByVal HDC As Long, ByVal X As Long, ByVal Y As Long) As Long

Declare Function SetPixelV Lib "gdi32" (ByVal HDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long

### Brightness

(21)

Listing Program Brightness :

Option Explicit

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long

Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal

hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long

Private Type BITMAP '14 bytes bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type

Private Type BITMAPINFOHEADER '40 bytes biSize As Long biWidth As Long biHeight As Long biPlanes As Integer biBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long biClrImportant As Long End Type

Private Type RGBQUAD rgbBlue As Byte rgbGreen As Byte rgbRed As Byte rgbReserved As Byte End Type

Private Type BITMAPINFO

End Type

Private Const DIB_RGB_COLORS = 0& Private Const BI_RGB = 0&

Private Const pixR As Integer = 3 Private Const pixG As Integer = 2

(22)

Private Const pixB As Integer = 1

Private Sub SetBrightness(ByVal pic1 As PictureBox, ByVal pic2 As PictureBox, ByVal brightness As Single)

Dim bitmap_info As BITMAPINFO Dim pixels() As Byte

Dim bytes_per_scanLine As Integer Dim pad_per_scanLine As Integer Dim X As Integer

Dim Y As Integer Dim fraction As Single With bitmap_info.bmiHeader .biSize = 40

.biWidth = Picture1.ScaleWidth

' Use negative height to scan top-down. .biHeight = -Picture1.ScaleHeight .biPlanes = 1

.biBitCount = 32

.biCompression = BI_RGB

bytes_per_scanLine = ((((.biWidth * .biBitCount) + 31) \ 32) * 4)

pad_per_scanLine = bytes_per_scanLine - (((.biWidth * .biBitCount) + 7) \ 8) .biSizeImage = bytes_per_scanLine * Abs(.biHeight)

End With

ReDim pixels(1 To 4, 1 To Picture1.ScaleWidth, 1 To Picture1.ScaleHeight) GetDIBits Picture1.hdc, Picture1.Image, _

0, Picture1.ScaleHeight, pixels(1, 1, 1), _ bitmap_info, DIB_RGB_COLORS

' Modify the pixels. If brightness < 0 Then ' Darken.

fraction = (100 + brightness) / 100 For Y = 1 To pic1.ScaleHeight For X = 1 To pic1.ScaleWidth

pixels(pixR, X, Y) = fraction * pixels(pixR, X, Y) pixels(pixG, X, Y) = fraction * pixels(pixG, X, Y) pixels(pixB, X, Y) = fraction * pixels(pixB, X, Y) Next X Next Y Else ' Brighten. fraction = brightness / 100 For Y = 1 To pic1.ScaleHeight For X = 1 To pic1.ScaleWidth pixels(pixR, X, Y) = pixels(pixR, X, Y) + _ fraction * (255 - pixels(pixR, X, Y)) pixels(pixG, X, Y) = pixels(pixG, X, Y) + _ fraction * (255 - pixels(pixG, X, Y)) pixels(pixB, X, Y) = pixels(pixB, X, Y) + _ fraction * (255 - pixels(pixB, X, Y)) Next X

(23)

' Display the result.

SetDIBits Picture2.hdc, Picture2.Image, _ 0, Picture1.ScaleHeight, pixels(1, 1, 1), _ bitmap_info, DIB_RGB_COLORS

Picture2.Picture = Picture2.Image End Sub

Me.Top = (Screen.Height - Height) / 2 Me.Left = (Screen.Width - Width) / 2 Picture1.ScaleMode = vbPixels Picture2.ScaleMode = vbPixels Picture1.AutoRedraw = True Picture2.AutoRedraw = True End Sub

Private Sub HScroll1_Change()

SetBrightness Picture1, Picture2, HScroll1.Value lblValue.Caption = Format\$(HScroll1.Value) End Sub

### Binary Image

(24)

Listing Program Binary Image : Option Explicit Dim Pixel Dim Rred Dim Ggreen Dim Bblue Dim Q As String Dim Temp As Integer Dim XXX As Integer Dim YYY As Integer Dim XX As Integer

Private Sub GetRGB(ByVal Col As String) On Error Resume Next

Bblue = Col \ (256 ^ 2)

Ggreen = (Col - Bblue * 256 ^ 2) \ 256

Rred = (Col - Bblue * 256 ^ 2 - Ggreen * 256) End Sub Private Sub Form_Load()

On Error Resume Next

Q = InputBox("Enter a value for black and white (0-255, high value will make a darker image)", "", "127")

Me.Top = (Screen.Height - Height) / 2 Me.Left = (Screen.Width - Width) / 2 If Q = "" Then Exit Sub

For YYY = 0 To Picture1.ScaleHeight - 1 For XXX = 0 To Picture1.ScaleWidth - 1 Pixel = GetPixel(Picture1.HDC, XXX, YYY) GetRGB Pixel

Temp = (Rred + Ggreen + Bblue) Temp = (Temp / 3) If Val(Temp) >= Q Then Pixel = vbWhite Else Pixel = vbBlack End If

SetPixelV Picture1.HDC, XXX, YYY, Pixel Next

Picture1.Refresh Next

Picture1.Refresh End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

JB = 1 CurX = X CurY = Y End Sub

(25)

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

JB = 0 End Sub

Module

(26)

## Daftar Pustaka

### Daftar Situs :

http://www.vb-helper.com/howto_watermark.html http://www.vb-helper.com/howto_adjust_brightness.html http://www.vbaccelerator.com/home/VB/Code/vbMedia/Image_Processi ng/Edge_Detection/article.asp http://www.vbaccelerator.com/home/VB/Code/vbMedia/Image_Processi ng/Binary_Image/article.asp

Memperbarui...

## Referensi

#### Pindai kode QR dengan aplikasi 1PDF untuk diunduh sekarang

Instal aplikasi 1PDF di