LAMPIRAN A
DATA SAMPEL
1. Data Latih No
Citra (.jpg)
1
No
Citra (.jpg)
2 Palmprint_April (1)
5
Palmprint_April (2)
Palmprint_April (5)
13
Palmprint_April (13)
17
21
Palmprint_April (15)
Palmprint_April (18)
Palmprint_April (16)
20
Palmprint_April (19)
23 Palmprint_Bobby (2)
Palmprint_April (12)
16
19
22 Palmprint_Bobby (1)
12
15
18
Palmprint_April (8)
Palmprint_April (11)
Palmprint_April (14)
Palmprint_April (17)
8
11
14
Palmprint_April (4)
Palmprint_April (7)
Palmprint_April (10)
Citra (.jpg)
4
7
10
No
Palmprint_April (3)
Palmprint_April (6)
Palmprint_April (9)
Citra (.jpg)
3
6
9
No
Palmprint_April (20)
24 Palmprint_Bobby (3)
Palmprint_Bobby (4)
Universitas Sumatera Utara
47
25
26 Palmprint_Bobby (5)
29
27 Palmprint_Bobby (6)
30 Palmprint_Bobby (9)
33
31
34
37
Palmprint_Cici (3)
Palmprint_Cici (6)
Palmprint_Cici (4)
48 Palmprint_Cici (7)
51 Palmprint_Cici (10)
Palmprint_Bobby (20)
44
47
50 Palmprint_Cici (9)
Palmprint_Bobby (19)
Palmprint_Cici (2)
Palmprint_Cici (5)
Palmprint_Bobby (16)
40
43
46
49
Palmprint_Bobby (15)
Palmprint_Bobby (18)
Palmprint_Cici (1)
Palmprint_Bobby (12)
36
39
42
45
Palmprint_Bobby (11)
Palmprint_Bobby (14)
Palmprint_Bobby (17)
Palmprint_Bobby (8)
32
35
38
41
Palmprint_Bobby (7)
Palmprint_Bobby (10)
Palmprint_Bobby (13)
28
Palmprint_Cici (8)
52 Palmprint_Cici (11)
Palmprint_Cici (12)
Universitas Sumatera Utara
48
53
54 Palmprint_Cici (13)
57
55 Palmprint_Cici (14)
58 Palmprint_Cici (17)
61
59
62
65
Palmprint_Irene (11)
Palmprint_Irene (14)
Palmprint_Irene (12)
76 Palmprint_Irene (15)
79 Palmprint_Irene (18)
Palmprint_Irene (8)
72
75
78 Palmprint_Irene (17)
Palmprint_Irene (7)
Palmprint_Irene (10)
Palmprint_Irene (13)
Palmprint_Irene (4)
68
71
74
77
Palmprint_Irene (3)
Palmprint_Irene (6)
Palmprint_Irene (9)
Palmprint_Cici (20)
64
67
70
73
Palmprint_Cici (19)
Palmprint_Irene (2)
Palmprint_Irene (5)
Palmprint_Cici (16)
60
63
66
69
Palmprint_Cici (15)
Palmprint_Cici (18)
Palmprint_Irene (1)
56
Palmprint_Irene (16)
80 Palmprint_Irene (19)
Palmprint_Irene (20)
Universitas Sumatera Utara
49
81
82 Palmprint_Irwan (1)
85
83 Palmprint_Irwan (2)
86 Palmprint_Irwan (5)
89
87
90
93
Palmprint_Irwan (19)
Palmprint_Rian (2)
Palmprint_Irwan (20)
104 Palmprint_Rian (3)
107 Palmprint_Rian (6)
Palmprint_Irwan (16)
100
103
106 Palmprint_Rian (5)
Palmprint_Irwan (15)
Palmprint_Irwan (18)
Palmprint_Rian (1)
Palmprint_Irwan (12)
96
99
102
105
Palmprint_Irwan (11)
Palmprint_Irwan (14)
Palmprint_Irwan (17)
Palmprint_Irwan (8)
92
95
98
101
Palmprint_Irwan (7)
Palmprint_Irwan (10)
Palmprint_Irwan (13)
Palmprint_Irwan (4)
88
91
94
97
Palmprint_Irwan (3)
Palmprint_Irwan (6)
Palmprint_Irwan (9)
84
Palmprint_Rian (4)
108 Palmprint_Rian (7)
Palmprint_Rian (8)
Universitas Sumatera Utara
50
109
110 Palmprint_Rian (9)
113
111 Palmprint_Rian (10)
114 Palmprint_Rian (13)
117
115
118
121
Palmprint_Vero (7)
Palmprint_Vero (10)
Palmprint_Vero (8)
132 Palmprint_Vero (11)
135 Palmprint_Vero (14)
Palmprint_Vero (4)
128
131
134 Palmprint_Vero (13)
Palmprint_Vero (3)
Palmprint_Vero (6)
Palmprint_Vero (9)
Palmprint_Rian (20)
124
127
130
133
Palmprint_Rian (19)
Palmprint_Vero (2)
Palmprint_Vero (5)
Palmprint_Rian (16)
120
123
126
129
Palmprint_Rian (15)
Palmprint_Rian (18)
Palmprint_Vero (1)
Palmprint_Rian (12)
116
119
122
125
Palmprint_Rian (11)
Palmprint_Rian (14)
Palmprint_Rian (17)
112
Palmprint_Vero (12)
136 Palmprint_Vero (15)
Palmprint_Vero (16)
Universitas Sumatera Utara
51
137
138 Palmprint_Vero (17)
141
139 Palmprint_Vero (18)
142 Palmprint_Yayuk (1)
145
143
146
149
Palmprint_Yayuk (11)
Palmprint_Yayuk (14)
Palmprint_Yayuk (12)
156 Palmprint_Yayuk (15)
159 Palmprint_Yayuk (18)
Palmprint_Yayuk (8)
152
155
158 Palmprint_Yayuk (17)
Palmprint_Yayuk (7)
Palmprint_Yayuk (10)
Palmprint_Yayuk (13)
Palmprint_Yayuk (4)
148
151
154
157
Palmprint_Yayuk (3)
Palmprint_Yayuk (6)
Palmprint_Yayuk (9)
Palmprint_Vero (20)
144
147
150
153
Palmprint_Vero (19)
Palmprint_Yayuk (2)
Palmprint_Yayuk (5)
140
Palmprint_Yayuk (16)
160 Palmprint_Yayuk (19)
Palmprint_Yayuk (20)
Universitas Sumatera Utara
52
2. Data uji tanpa noise No
Citra (.jpg)
1
No
Citra (.jpg)
2 A (1)
5
A (2)
A (5)
13
C (1) 17
21
25
29
I (5)
IW (2)
I (6) 28
IW (3) 31
IW (6)
I (2)
24
27
30 IW (5)
20
23
26
C (4)
I (1)
I (4)
IW (1)
16
19
22
B (6)
C (3)
C (6)
I (3)
12
15
18
B (2)
B (5)
C (2)
C (5)
8
11
14
A (4)
B (1)
B (4)
Citra (.jpg)
4
7
10
No
A (3)
A (6)
B (3)
Citra (.jpg)
3
6
9
No
IW (4) 32
R (1)
R (2)
Universitas Sumatera Utara
53
No
Citra (.jpg)
33
No
Citra (.jpg)
34
R (3) 37
R (4)
V (1)
45 Y (3)
40
43
46
R (6)
V (3)
V (6)
V (4) 44
Y (1) 47
Y (4)
Citra (.jpg)
36
39
42
No
R (5)
V (2)
V (5)
Citra (.jpg)
35
38
41
No
Y (2) 48
Y (5)
Y (6)
3. Data uji memiliki noise No
Citra (.jpg)
49
No
Citra (.jpg)
50 A (7)
53
A (8)
B (7)
A (9)
B (8)
Citra (.jpg)
A (10)
56
B (9) 59
C (8)
No 52
55
58 C (7)
Citra (.jpg)
51
54
57
No
B (10) 60
C (9)
C (10)
Universitas Sumatera Utara
54
No
Citra (.jpg)
61
No
Citra (.jpg)
62 I (7)
65
I (8)
IW (7)
73 V (7) 77
R (9)
V (8)
R (10) 76
V (9) 79
Y (8)
IW (10)
72
75
78 Y (7)
68
71
74
I (10)
IW (9)
R (8)
Citra (.jpg)
64
67
70
No
I (9)
IW (8)
R (7)
Citra (.jpg)
63
66
69
No
V (10) 80
Y (9)
Y (10)
Universitas Sumatera Utara
LAMPIRAN B
LISTING PROGRAM
1.
Modul Filter Gambar import java.io.File; import javax.swing.filechooser.FileFilter; //class yang digunakan untuk menyaring format citra hanya .jpg saja public class filterGambar extends FileFilter { public filterGambar() {} public boolean accept (File f) { if(f.isDirectory()) { return true; } //pengubahan String dari nama citra menjadi huruf kapital String file = f.getName().toUpperCase(); if(file.endsWith(".JPG")) //kondisi jika file citra/image memiliki ekstensi .jpg { return true; } return false; } public String getDescription(){ return "Image File"; } }
Universitas Sumatera Utara
56
2.
Modul pelatihan (grayscale, deteksi tepi, dan binerisasi) public class formUtama3 extends javax.swing.JFrame { filterGambar filter = new filterGambar(); BufferedImage originalImage; BufferedImage grayscaleImage, normalisasiIntensitasImage, edgeImage; JFileChooser fc = new JFileChooser();
/*1. Method RGB2GS : mengubah citra RGB menjadi grayscale*/ public void RGB2GS(BufferedImage grayscaleImage){ int alpha, r, g, b; /*variable width : mengambil nilai lebar dari citra * variable height : mengambil nilai tinggi dari citra*/ int width = originalImage.getWidth(); int height = originalImage.getHeight();
//Membuat Buffered image untuk image grayscale BufferedImage im = new BufferedImage (width,height,BufferedImage.TYPE_BYTE_GRAY); for(int i=0; i < width; i++){ for(int j=0; j < height; j++){ //mendapatkan nilai RGB dari originalImage alpha = originalImage.getRGB(i,j); r = (alpha & 0x00ff0000) >> 16; //mendapatkan nilai red (merah) g = (alpha & 0x0000ff00) >> 8; //mendapatkan nilai green (hijau) b = alpha & 0x000000ff; //mendapatkan nilai blue (biru) //menghitung nilai gray image float gray = (float) (0.3 * r + 0.59 * g + 0.11 * b); } } // membuat dan menyimpan citra grayscale ke dalam folder ImageIO.write(im,"JPG",new File ("3. Citra Hasil Latih/1. Grayscale/newGrayLatih.jpg")); } /*2. method setCannyEdgeDetector untuk mengubah citra grayscale menjadi citra deteksi tepi*/ public void setCannyEdgeDetector(BufferedImage edges){ //file image grayscale untuk dibentuk citra deteksi tepi File file = new File("3. Citra Hasil Latih/1. Grayscale/newGrayLatih.jpg");
Universitas Sumatera Utara
57
BufferedImage frame = ImageIO.read(file);
//membuat sebuah objek bernama detector dari Class CannyEdge Detector CannyEdgeDetector detector = new CannyEdgeDetector();
//tetapkan low dan high threshold detector.setLowThreshold(0.5f); detector.setHighThreshold(1.0f);
//proses pendeteksian tepi detector.setSourceImage(frame); //pengambilan sumber image detector.process(); //method proses deteksi tepi edges = detector.getEdgesImage(); // membuat dan menyimpan citra deteksi tepi ke dalam folder ImageIO.write(edges,"PNG",new File ("3. Citra Hasil Latih/2. Deteksi Tepi/newEdgeLatih.png")); }
/*3. Method setBinerisasi untuk mengubah citra deteksi tepi menjadi citra biner*/ public void setBinerisasi(){ File file = new File("3. Citra Hasil Latih/2. Deteksi Tepi/newEdgeLatih.png"); BufferedImage imageBiner = ImageIO.read(file); int lebar = imageBiner.getWidth(); int tinggi = imageBiner.getHeight(); int threshold = 150; //nilai threshold yang ditetapkan BufferedImage im = new BufferedImage (lebar,tinggi,BufferedImage.TYPE_BYTE_GRAY); for(int i = 0; i < lebar; i++){ for (int j=0; j < tinggi; j++){ //kondisi jika nilai image lebih besar dari nilai threshold if(image.getRGB(j,i) >= threshold) { image.getRGB(j,i) = 255; }
//kondisi jika nilai image lebih kecil dari nilai threshold else if (image.getRGB(j,i) < threshold)
Universitas Sumatera Utara
58
{ image.getRGB(j,i)= 0; } } } // membuat dan menyimpan citra biner ke dalam folder ImageIO.write(im,"PNG",new File ("3. Citra Hasil Latih/3. Biner/newBinerLatih.png")); }
//method setEkstraksi untuk mendapatkan nilai fitur dari citra yang diproses public void setEkstraksi(){ File file = new File("3. Citra Hasil Latih/3. Biner/newBinerLatih.png"); //mengambil file yang dihitung fiturnya BufferedImage image = ImageIO.read(file); int lebar = image.getWidth(); int tinggi = image.getHeight();
int[][] gambar = new int[tinggi][lebar]; //membuat array 2 dimensi dengan nama //variable gambar
for (int row = 0; row < tinggi; row++) { //perulangan untuk membaca piksel baris //dan kolom dari citra for (int col = 0; col < lebar; col++) { gambar[row][col] = image.getRGB(col, row); //kondisi saat image memiliki nilai biner -16777216 (hitam) set menjadi nilai biner if(gambar[row][col] == -16777216) gambar[row][col] = 1; //kondisi saat image memiliki nilai biner -1(putih) set menjadi nilai biner 0 else if(gambar[row][col] == -1) gambar[row][col] = 0; } } //inisialisasi variable untuk perhitungan pixel dan blok int index_i , index_j, nilai_pixel, jlh_pixel, kolom, hasil_index, temp_hasil = 0; int total_block = 10; //jumlah blok 10x10 blok int max_pixel_block = 20; //jumlah piksel dalam 1 blok yaitu 20x20 piksel
Universitas Sumatera Utara
59
double[] hasil = new double[100]; //array dengan variable hasil yang memiliki //panjang array 100
for(int h=0; h < total_block; h++) //perulangan pada kolom blok { for(int i= 0; i < total_block; i++) //perulangan pada baris blok { nilai_pixel = 0; jlh_pixel = 0; index_i = h * max_pixel_block; temp_hasil = 0;
for(int j = index_i; j
// array hasil utk menyimpan nilai fitur rata-rata hasil[hasil_index] = (double) temp_hasil / 400; //menampilkan hasil index di textArea variable txtRataRata txtRataRata.setText(txtRataRata.getText()+""+hasil[hasil_index]+"\n"); hasil_index++; //melanjutkan nilai hasil dengan index berikutnya kolom++; //perhitungan blok di kolom berikutnya } } } }
Class: CannyEdgeDetector.java public class CannyEdgeDetector { private final static float GAUSSIAN_CUT_OFF = 0.005f; private final static float MAGNITUDE_SCALE = 100F; private final static float MAGNITUDE_LIMIT = 1000F;
Universitas Sumatera Utara
60
private final static int MAGNITUDE_MAX = (int) (MAGNITUDE_SCALE * MAGNITUDE_LIMIT);
private int height; private int width; private int picsize; private int[] data; private int[] magnitude; private BufferedImage sourceImage; private BufferedImage edgesImage;
private float gaussianKernelRadius; private float lowThreshold; private float highThreshold; private int gaussianKernelWidth; private boolean contrastNormalized;
private float[] xConv; private float[] yConv; private float[] xGradient; private float[] yGradient;
public CannyEdgeDetector() { lowThreshold = 2.5f; highThreshold = 7.5f; gaussianKernelRadius = 2f; gaussianKernelWidth = 16; contrastNormalized = false; } /*method process berisi proses yang dilakukan untuk mencari deteksi tepi*/ public void process() { width = sourceImage.getWidth(); height = sourceImage.getHeight(); picsize = width * height;
initArrays(); //komponen yang terdapat didalamnya
//proses-proses untuk mendapatkan citra deteksi tepi computeGradients(gaussianKernelRadius, gaussianKernelWidth);
Universitas Sumatera Utara
61
int low = Math.round(lowThreshold * MAGNITUDE_SCALE); int high = Math.round(highThreshold * MAGNITUDE_SCALE); performHysteresis(low, high); //proses hysteresis menghilangkan tepi yang rusak thresholdEdges(); writeEdges(data); }
private void initArrays() { if (data == null || picsize != data.length) { data = new int[picsize]; magnitude = new int[picsize]; xConv = new float[picsize]; yConv = new float[picsize]; xGradient = new float[picsize]; yGradient = new float[picsize]; } } // memproses penerapan filter gaussian private void computeGradients(float kernelRadius, int kernelWidth) { //perhitungan dengan matriks konvolusi Gaussian float kernel[] = new float[kernelWidth]; float diffKernel[] = new float[kernelWidth]; int kwidth; for (kwidth = 0; kwidth < kernelWidth; kwidth++) { float g1 = gaussian(kwidth, kernelRadius); if (g1 <= GAUSSIAN_CUT_OFF && kwidth >= 2) break; float g2 = gaussian(kwidth - 0.5f, kernelRadius); float g3 = gaussian(kwidth + 0.5f, kernelRadius); kernel[kwidth] = (g1 + g2 + g3) / 3f / (2f * (float) Math.PI * kernelRadius * kernelRadius); diffKernel[kwidth] = g3 - g2; }
int initX = kwidth - 1; int maxX = width - (kwidth - 1); int initY = width * (kwidth - 1); int maxY = width * (height - (kwidth - 1));
//mencari nilai dan arah tepi dengan matriks konvolusi x dan y
Universitas Sumatera Utara
62
for (int x = initX; x < maxX; x++) { for (int y = initY; y < maxY; y += width) { int index = x + y; float sumX = data[index] * kernel[0]; float sumY = sumX; int xOffset = 1; int yOffset = width; for(; xOffset < kwidth ;) { sumY += kernel[xOffset] * (data[index - yOffset] + data[index + yOffset]); sumX += kernel[xOffset] * (data[index - xOffset] + data[index + xOffset]); yOffset += width; xOffset++; } yConv[index] = sumY; xConv[index] = sumX; } } for (int x = initX; x < maxX; x++) { for (int y = initY; y < maxY; y += width) { float sum = 0f; int index = x + y; for (int i = 1; i < kwidth; i++) sum += diffKernel[i] * (yConv[index - i] - yConv[index + i]); xGradient[index] = sum; } } for (int x = kwidth; x < width - kwidth; x++) { for (int y = initY; y < maxY; y += width) { float sum = 0.0f; int index = x + y; int yOffset = width; for (int i = 1; i < kwidth; i++) { sum += diffKernel[i] * (xConv[index - yOffset] - xConv[index + yOffset]); yOffset += width; } yGradient[index] = sum;
Universitas Sumatera Utara
63
} } initX = kwidth; maxX = width - kwidth; initY = width * kwidth; maxY = width * (height - kwidth); /*perulangan untuk menghubungkan arah tepi (North, South, West, East, dst)*/ for (int x = initX; x < maxX; x++) { for (int y = initY; y < maxY; y += width) { int index = x + y; int indexN = index - width; int indexS = index + width; int indexW = index - 1; int indexE = index + 1; int indexNW = indexN - 1; int indexNE = indexN + 1; int indexSW = indexS - 1; int indexSE = indexS + 1;
float xGrad = xGradient[index]; float yGrad = yGradient[index]; float gradMag = hypot(xGrad, yGrad);
// non-maximal suppression : penelusuran tepi yang ada di dalam arah tepi float nMag = hypot(xGradient[indexN], yGradient[indexN]); float sMag = hypot(xGradient[indexS], yGradient[indexS]); float wMag = hypot(xGradient[indexW], yGradient[indexW]); float eMag = hypot(xGradient[indexE], yGradient[indexE]); float neMag = hypot(xGradient[indexNE], yGradient[indexNE]); float seMag = hypot(xGradient[indexSE], yGradient[indexSE]); float swMag = hypot(xGradient[indexSW], yGradient[indexSW]); float nwMag = hypot(xGradient[indexNW], yGradient[indexNW]); float tmp; if (xGrad * yGrad <= (float) 0 /*(1)*/ ? Math.abs(xGrad) >= Math.abs(yGrad) /*(2)*/ ? (tmp = Math.abs(xGrad * gradMag)) >= Math.abs(yGrad * neMag - (xGrad + yGrad) * eMag) /*(3)*/ && tmp > Math.abs(yGrad * swMag - (xGrad + yGrad) * wMag) /*(4)*/
Universitas Sumatera Utara
64
: (tmp = Math.abs(yGrad * gradMag)) >= Math.abs(xGrad * neMag - (yGrad + xGrad) * nMag) /*(3)*/ && tmp > Math.abs(xGrad * swMag - (yGrad + xGrad) * sMag) /*(4)*/ : Math.abs(xGrad) >= Math.abs(yGrad) /*(2)*/ ? (tmp = Math.abs(xGrad * gradMag)) >= Math.abs(yGrad * seMag +
(xGrad - yGrad) *
eMag) /*(3)*/ && tmp > Math.abs(yGrad * nwMag + (xGrad - yGrad) * wMag) /*(4)*/ : (tmp = Math.abs(yGrad * gradMag)) >= Math.abs(xGrad * seMag +
(yGrad - xGrad) *
sMag) /*(3)*/ && tmp > Math.abs(xGrad * nwMag + (yGrad - xGrad) * nMag) /*(4)*/ ) { magnitude[index] = gradMag >= MAGNITUDE_LIMIT ? MAGNITUDE_MAX : (int) (MAGNITUDE_SCALE * gradMag); } else { magnitude[index] = 0; } } }
private float hypot(float x, float y) { return (float) Math.hypot(x, y); }
private float gaussian(float x, float sigma) { //rumus untuk filter Gaussian return (float) Math.exp(-(x * x) / (2f * sigma * sigma)); }
/*proses hysteresis private void performHysteresis(int low, int high) { Arrays.fill(data, 0); int offset = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (data[offset] == 0 && magnitude[offset] >= high) { follow(x, y, offset, low); }
Universitas Sumatera Utara
65
offset++; } } }
private void follow(int x1, int y1, int i1, int threshold) { int x0 = x1 == 0 ? x1 : x1 - 1; int x2 = x1 == width - 1 ? x1 : x1 + 1; int y0 = y1 == 0 ? y1 : y1 - 1; int y2 = y1 == height -1 ? y1 : y1 + 1;
data[i1] = magnitude[i1]; for (int x = x0; x <= x2; x++) { for (int y = y0; y <= y2; y++) { int i2 = x + y * width; if ((y != y1 || x != x1) && data[i2] == 0 && magnitude[i2] >= threshold) { follow(x, y, i2, threshold); return; } } } } //penentuan nilai threshold dalam menetapkan tepi atau tidak private void thresholdEdges() { for (int i = 0; i < picsize; i++) { data[i] = data[i] > 0 ? -1 : 0xff000000; } } //membuat edge /tepi citra private void writeEdges(int pixels[]) { if (edgesImage == null) { edgesImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } edgesImage.getWritableTile(0, 0).setDataElements(0, 0, width, height, pixels); }
Universitas Sumatera Utara
66
3.
Modul Pengujian Modul untuk proses pengolahan citra sama dengan modul pelatihan hanya berbeda pada folder target penyimpanan. Semua citra hasil pengujian akan disimpan di dalam folder hasil citra uji.
//method untuk mencari jarak Euclidean ternormalisasi public void cariJarak(){ String nilaiUji = ambilFiturUji(); String[] potongUji = nilaiUji.split("; "); Double[] u = new Double[potongUji.length]; Double uNorm = 0.0; double min; double d = 0.0;
/* array untuk menyimpan nilai jarak yang akan diuji*/ Double[] arrayD = new Double[160]; int h; for( h=0; h < potongUji.length; h++) //perulangan saat pengambilan fitur citra uji
{
u[h] = Double.parseDouble(potongUji[h]); 2
uNorm += (double) u[h] * u[h]; //sigma uh (hitung sigma uNorm) } 2 1/2
uNorm = (double) Math.sqrt(uNorm); //(sigma (uh ))
/* perulangan untuk mengambil fitur yang telah dilatih dalam database (sebanyak 160 fitur) */ for(int i=0; i < arrayD.length; i++) { String nilaiLatih = ambilFiturLatih(i+1); //nilai fitur latih yang diambil //mulai dari nomor indeks-1 String[] potongLatih = nilaiLatih.split("; ");
/*membuat array v dengan panjang sebesar fitur latih yaitu 100*/ Double[] v = new Double[potongLatih.length];
Double vNorm =
0.0;
for(int j=0; j < v.length; j++) //perulangan untuk menghitung sigma vNorm { v[j] = Double.parseDouble(potongLatih[j]); 2
vNorm += (double) v[j] * v[j]; // sigma vj (hitung sigma vNorm) }
Universitas Sumatera Utara
67
2 1/2
vNorm = (double) Math.sqrt(vNorm); //(sigma (vj ))
/*perulangan menghitung nilai jarak Euclidean ternormalisasi*/ for(int j=0; j < u.length; j++) { //hitung jarak (d) d += (double) (u[j]/uNorm-v[j]/vNorm)*(u[j]/uNorm-v[j]/vNorm); d = (double) Math.sqrt(d); } arrayD[i] = (double) d; //menyimpan nilai setiap indeks arrayD dengan nilai //hasil jarak (d) System.out.println(arrayD[i]); //cetak nilai semua indeks dalam arrayD }
/*kondisi pencarian nilai jarak (d) minimum*/ min = arrayD[0];
//inisialisasi nilai min = nilai indeks ke-0 arrayD
for (int k=1; k <arrayD.length; k++){ // pengecekan disetiap indeks arrayD if(arrayD[k] < min){ //kondisi saat nilai arrayD lebih kecil dari nilai min min = arrayD[k]; } } System.out.println("hasil jarak terkecil: "+min);
Universitas Sumatera Utara