Последняя активность 1698157880

moepoi's Avatar moepoi ревизий этого фрагмента 1698157880. К ревизии

1 file changed, 71 insertions, 466 deletions

1.m

@@ -1,481 +1,86 @@
1 1 clear; clc;
2 2
3 - % Load image (Type : UINT8)
4 - gambar1 = imread('Banana/1.jpg');
5 - gambar2 = imread('Banana/2.jpg');
6 - gambar3 = imread('Banana/3.jpg');
7 - gambar4 = imread('Banana/4.jpg');
8 - gambar5 = imread('Banana/5.jpg');
9 - gambar6 = imread('Banana/6.jpg');
10 - gambar7 = imread('Banana/7.jpg');
11 - gambar8 = imread('Banana/8.jpg');
12 - gambar9 = imread('Banana/9.jpg');
13 - gambar10 = imread('Banana/10.jpg');
14 - gambar11 = imread('Kiwi/1.jpg');
15 - gambar12 = imread('Kiwi/2.jpg');
16 - gambar13 = imread('Kiwi/3.jpg');
17 - gambar14 = imread('Kiwi/4.jpg');
18 - gambar15 = imread('Kiwi/5.jpg');
19 - gambar16 = imread('Kiwi/6.jpg');
20 - gambar17 = imread('Kiwi/7.jpg');
21 - gambar18 = imread('Kiwi/8.jpg');
22 - gambar19 = imread('Kiwi/9.jpg');
23 - gambar20 = imread('Kiwi/10.jpg');
24 - gambar21 = imread('Orange/1.jpg');
25 - gambar22 = imread('Orange/2.jpg');
26 - gambar23 = imread('Orange/3.jpg');
27 - gambar24 = imread('Orange/4.jpg');
28 - gambar25 = imread('Orange/5.jpg');
29 - gambar26 = imread('Orange/6.jpg');
30 - gambar27 = imread('Orange/7.jpg');
31 - gambar28 = imread('Orange/8.jpg');
32 - gambar29 = imread('Orange/9.jpg');
33 - gambar30 = imread('Orange/10.jpg');
34 -
35 - % Konversi UINT8 menjadi double agar dapat di operasikan komputasinya
36 - gambar1 = double(gambar1);
37 - gambar2 = double(gambar2);
38 - gambar3 = double(gambar3);
39 - gambar4 = double(gambar4);
40 - gambar5 = double(gambar5);
41 - gambar6 = double(gambar6);
42 - gambar7 = double(gambar7);
43 - gambar8 = double(gambar8);
44 - gambar9 = double(gambar9);
45 - gambar10 = double(gambar10);
46 - gambar11 = double(gambar11);
47 - gambar12 = double(gambar12);
48 - gambar13 = double(gambar13);
49 - gambar14 = double(gambar14);
50 - gambar15 = double(gambar15);
51 - gambar16 = double(gambar16);
52 - gambar17 = double(gambar17);
53 - gambar18 = double(gambar18);
54 - gambar19 = double(gambar19);
55 - gambar20 = double(gambar20);
56 - gambar21 = double(gambar21);
57 - gambar22 = double(gambar22);
58 - gambar23 = double(gambar23);
59 - gambar24 = double(gambar24);
60 - gambar25 = double(gambar25);
61 - gambar26 = double(gambar26);
62 - gambar27 = double(gambar27);
63 - gambar28 = double(gambar28);
64 - gambar29 = double(gambar29);
65 - gambar30 = double(gambar30);
66 -
67 - % 1,2,3 itu layer, RGB itu warnanya
68 - gambar1R = gambar1(:,:,1); % layer 1
69 - gambar1G = gambar1(:,:,2); % layer 2
70 - gambar1B = gambar1(:,:,3); % layer 3
71 -
72 - gambar2R = gambar2(:,:,1);
73 - gambar2G = gambar2(:,:,2);
74 - gambar2B = gambar2(:,:,3);
75 -
76 - gambar3R = gambar3(:,:,1);
77 - gambar3G = gambar3(:,:,2);
78 - gambar3B = gambar3(:,:,3);
79 -
80 - gambar4R = gambar4(:,:,1);
81 - gambar4G = gambar4(:,:,2);
82 - gambar4B = gambar4(:,:,3);
83 -
84 - gambar5R = gambar5(:,:,1);
85 - gambar5G = gambar5(:,:,2);
86 - gambar5B = gambar5(:,:,3);
87 -
88 - gambar6R = gambar6(:,:,1);
89 - gambar6G = gambar6(:,:,2);
90 - gambar6B = gambar6(:,:,3);
91 -
92 - gambar7R = gambar7(:,:,1);
93 - gambar7G = gambar7(:,:,2);
94 - gambar7B = gambar7(:,:,3);
95 -
96 - gambar8R = gambar8(:,:,1);
97 - gambar8G = gambar8(:,:,2);
98 - gambar8B = gambar8(:,:,3);
99 -
100 - gambar9R = gambar9(:,:,1);
101 - gambar9G = gambar9(:,:,2);
102 - gambar9B = gambar9(:,:,3);
103 -
104 - gambar10R = gambar10(:,:,1);
105 - gambar10G = gambar10(:,:,2);
106 - gambar10B = gambar10(:,:,3);
107 -
108 - gambar11R = gambar11(:,:,1);
109 - gambar11G = gambar11(:,:,2);
110 - gambar11B = gambar11(:,:,3);
111 -
112 - gambar12R = gambar12(:,:,1);
113 - gambar12G = gambar12(:,:,2);
114 - gambar12B = gambar12(:,:,3);
115 -
116 - gambar13R = gambar13(:,:,1);
117 - gambar13G = gambar13(:,:,2);
118 - gambar13B = gambar13(:,:,3);
119 -
120 - gambar14R = gambar14(:,:,1);
121 - gambar14G = gambar14(:,:,2);
122 - gambar14B = gambar14(:,:,3);
123 -
124 - gambar15R = gambar15(:,:,1);
125 - gambar15G = gambar15(:,:,2);
126 - gambar15B = gambar15(:,:,3);
127 -
128 - gambar16R = gambar16(:,:,1);
129 - gambar16G = gambar16(:,:,2);
130 - gambar16B = gambar16(:,:,3);
131 -
132 - gambar17R = gambar17(:,:,1);
133 - gambar17G = gambar17(:,:,2);
134 - gambar17B = gambar17(:,:,3);
135 -
136 - gambar18R = gambar18(:,:,1);
137 - gambar18G = gambar18(:,:,2);
138 - gambar18B = gambar18(:,:,3);
139 -
140 - gambar19R = gambar19(:,:,1);
141 - gambar19G = gambar19(:,:,2);
142 - gambar19B = gambar19(:,:,3);
143 -
144 - gambar20R = gambar20(:,:,1);
145 - gambar20G = gambar20(:,:,2);
146 - gambar20B = gambar20(:,:,3);
147 -
148 - gambar21R = gambar21(:,:,1);
149 - gambar21G = gambar21(:,:,2);
150 - gambar21B = gambar21(:,:,3);
151 -
152 - gambar22R = gambar22(:,:,1);
153 - gambar22G = gambar22(:,:,2);
154 - gambar22B = gambar22(:,:,3);
155 -
156 - gambar23R = gambar23(:,:,1);
157 - gambar23G = gambar23(:,:,2);
158 - gambar23B = gambar23(:,:,3);
159 -
160 - gambar24R = gambar24(:,:,1);
161 - gambar24G = gambar24(:,:,2);
162 - gambar24B = gambar24(:,:,3);
163 -
164 - gambar25R = gambar25(:,:,1);
165 - gambar25G = gambar25(:,:,2);
166 - gambar25B = gambar25(:,:,3);
167 -
168 - gambar26R = gambar26(:,:,1);
169 - gambar26G = gambar26(:,:,2);
170 - gambar26B = gambar26(:,:,3);
171 -
172 - gambar27R = gambar27(:,:,1);
173 - gambar27G = gambar27(:,:,2);
174 - gambar27B = gambar27(:,:,3);
175 -
176 - gambar28R = gambar28(:,:,1);
177 - gambar28G = gambar28(:,:,2);
178 - gambar28B = gambar28(:,:,3);
179 -
180 - gambar29R = gambar29(:,:,1);
181 - gambar29G = gambar29(:,:,2);
182 - gambar29B = gambar29(:,:,3);
183 -
184 - gambar30R = gambar30(:,:,1);
185 - gambar30G = gambar30(:,:,2);
186 - gambar30B = gambar30(:,:,3);
187 -
188 - [n,p] = size(gambar1R);
189 -
190 - k = 1;
191 - for i=1:n
192 - for j=1:p
193 - vgambar1R(k,1) = gambar1R(i,j);
194 - vgambar1G(k,1) = gambar1G(i,j);
195 - vgambar1B(k,1) = gambar1B(i,j);
196 - mat_gambar1 = [vgambar1R, vgambar1G, vgambar1B];
197 -
198 -
199 - vgambar2R(k,1) = gambar2R(i,j);
200 - vgambar2G(k,1) = gambar2G(i,j);
201 - vgambar2B(k,1) = gambar2B(i,j);
202 - mat_gambar2 = [vgambar2R, vgambar2G, vgambar2B];
203 -
204 -
205 - vgambar3R(k,1) = gambar3R(i,j);
206 - vgambar3G(k,1) = gambar3G(i,j);
207 - vgambar3B(k,1) = gambar3B(i,j);
208 - mat_gambar3 = [vgambar3R, vgambar3G, vgambar3B];
209 -
210 -
211 - vgambar4R(k,1) = gambar4R(i,j);
212 - vgambar4G(k,1) = gambar4G(i,j);
213 - vgambar4B(k,1) = gambar4B(i,j);
214 - mat_gambar4 = [vgambar4R, vgambar4G, vgambar4B];
215 -
216 -
217 - vgambar5R(k,1) = gambar5R(i,j);
218 - vgambar5G(k,1) = gambar5G(i,j);
219 - vgambar5B(k,1) = gambar5B(i,j);
220 - mat_gambar5 = [vgambar5R, vgambar5G, vgambar5B];
221 -
222 -
223 - vgambar6R(k,1) = gambar6R(i,j);
224 - vgambar6G(k,1) = gambar6G(i,j);
225 - vgambar6B(k,1) = gambar6B(i,j);
226 - mat_gambar6 = [vgambar6R, vgambar6G, vgambar6B];
227 -
228 -
229 - vgambar7R(k,1) = gambar7R(i,j);
230 - vgambar7G(k,1) = gambar7G(i,j);
231 - vgambar7B(k,1) = gambar7B(i,j);
232 - mat_gambar7 = [vgambar7R, vgambar7G, vgambar7B];
233 -
234 -
235 - vgambar8R(k,1) = gambar8R(i,j);
236 - vgambar8G(k,1) = gambar8G(i,j);
237 - vgambar8B(k,1) = gambar8B(i,j);
238 - mat_gambar8 = [vgambar8R, vgambar8G, vgambar8B];
239 -
240 -
241 - vgambar9R(k,1) = gambar9R(i,j);
242 - vgambar9G(k,1) = gambar9G(i,j);
243 - vgambar9B(k,1) = gambar9B(i,j);
244 - mat_gambar9 = [vgambar9R, vgambar9G, vgambar9B];
245 -
246 -
247 - vgambar10R(k,1) = gambar10R(i,j);
248 - vgambar10G(k,1) = gambar10G(i,j);
249 - vgambar10B(k,1) = gambar10B(i,j);
250 - mat_gambar10 = [vgambar10R, vgambar10G, vgambar10B];
251 -
252 -
253 - vgambar11R(k,1) = gambar11R(i,j);
254 - vgambar11G(k,1) = gambar11G(i,j);
255 - vgambar11B(k,1) = gambar11B(i,j);
256 - mat_gambar11 = [vgambar11R, vgambar11G, vgambar11B];
257 -
258 -
259 - vgambar12R(k,1) = gambar12R(i,j);
260 - vgambar12G(k,1) = gambar12G(i,j);
261 - vgambar12B(k,1) = gambar12B(i,j);
262 - mat_gambar12 = [vgambar12R, vgambar12G, vgambar12B];
263 -
264 -
265 - vgambar13R(k,1) = gambar13R(i,j);
266 - vgambar13G(k,1) = gambar13G(i,j);
267 - vgambar13B(k,1) = gambar13B(i,j);
268 - mat_gambar13 = [vgambar13R, vgambar13G, vgambar13B];
269 -
270 -
271 - vgambar14R(k,1) = gambar14R(i,j);
272 - vgambar14G(k,1) = gambar14G(i,j);
273 - vgambar14B(k,1) = gambar14B(i,j);
274 - mat_gambar14 = [vgambar14R, vgambar14G, vgambar14B];
275 -
276 -
277 - vgambar15R(k,1) = gambar15R(i,j);
278 - vgambar15G(k,1) = gambar15G(i,j);
279 - vgambar15B(k,1) = gambar15B(i,j);
280 - mat_gambar15 = [vgambar15R, vgambar15G, vgambar15B];
281 -
282 -
283 - vgambar16R(k,1) = gambar16R(i,j);
284 - vgambar16G(k,1) = gambar16G(i,j);
285 - vgambar16B(k,1) = gambar16B(i,j);
286 - mat_gambar16 = [vgambar16R, vgambar16G, vgambar16B];
287 -
288 -
289 - vgambar17R(k,1) = gambar17R(i,j);
290 - vgambar17G(k,1) = gambar17G(i,j);
291 - vgambar17B(k,1) = gambar17B(i,j);
292 - mat_gambar17 = [vgambar17R, vgambar17G, vgambar17B];
293 -
294 -
295 - vgambar18R(k,1) = gambar18R(i,j);
296 - vgambar18G(k,1) = gambar18G(i,j);
297 - vgambar18B(k,1) = gambar18B(i,j);
298 - mat_gambar18 = [vgambar18R, vgambar18G, vgambar18B];
299 -
300 -
301 - vgambar19R(k,1) = gambar19R(i,j);
302 - vgambar19G(k,1) = gambar19G(i,j);
303 - vgambar19B(k,1) = gambar19B(i,j);
304 - mat_gambar19 = [vgambar19R, vgambar19G, vgambar19B];
305 -
306 -
307 - vgambar20R(k,1) = gambar20R(i,j);
308 - vgambar20G(k,1) = gambar20G(i,j);
309 - vgambar20B(k,1) = gambar20B(i,j);
310 - mat_gambar20 = [vgambar20R, vgambar20G, vgambar20B];
311 -
312 -
313 - vgambar21R(k,1) = gambar21R(i,j);
314 - vgambar21G(k,1) = gambar21G(i,j);
315 - vgambar21B(k,1) = gambar21B(i,j);
316 - mat_gambar21 = [vgambar21R, vgambar21G, vgambar21B];
317 -
318 - vgambar22R(k,1) = gambar22R(i,j);
319 - vgambar22G(k,1) = gambar22G(i,j);
320 - vgambar22B(k,1) = gambar22B(i,j);
321 - mat_gambar22 = [vgambar22R, vgambar22G, vgambar22B];
322 -
323 - vgambar23R(k,1) = gambar23R(i,j);
324 - vgambar23G(k,1) = gambar23G(i,j);
325 - vgambar23B(k,1) = gambar23B(i,j);
326 - mat_gambar23 = [vgambar23R, vgambar23G, vgambar23B];
327 -
328 - vgambar24R(k,1) = gambar24R(i,j);
329 - vgambar24G(k,1) = gambar24G(i,j);
330 - vgambar24B(k,1) = gambar24B(i,j);
331 - mat_gambar24 = [vgambar24R, vgambar24G, vgambar24B];
332 -
333 - vgambar25R(k,1) = gambar25R(i,j);
334 - vgambar25G(k,1) = gambar25G(i,j);
335 - vgambar25B(k,1) = gambar25B(i,j);
336 - mat_gambar25 = [vgambar25R, vgambar25G, vgambar25B];
337 -
338 - vgambar26R(k,1) = gambar26R(i,j);
339 - vgambar26G(k,1) = gambar26G(i,j);
340 - vgambar26B(k,1) = gambar26B(i,j);
341 - mat_gambar26 = [vgambar26R, vgambar26G, vgambar26B];
342 -
343 - vgambar27R(k,1) = gambar27R(i,j);
344 - vgambar27G(k,1) = gambar27G(i,j);
345 - vgambar27B(k,1) = gambar27B(i,j);
346 - mat_gambar27 = [vgambar27R, vgambar27G, vgambar27B];
347 -
348 - vgambar28R(k,1) = gambar28R(i,j);
349 - vgambar28G(k,1) = gambar28G(i,j);
350 - vgambar28B(k,1) = gambar28B(i,j);
351 - mat_gambar28 = [vgambar28R, vgambar28G, vgambar28B];
352 -
353 - vgambar29R(k,1) = gambar29R(i,j);
354 - vgambar29G(k,1) = gambar29G(i,j);
355 - vgambar29B(k,1) = gambar29B(i,j);
356 - mat_gambar29 = [vgambar29R, vgambar29G, vgambar29B];
357 -
358 - vgambar30R(k,1) = gambar30R(i,j);
359 - vgambar30G(k,1) = gambar30G(i,j);
360 - vgambar30B(k,1) = gambar30B(i,j);
361 - mat_gambar30 = [vgambar30R, vgambar30G, vgambar30B];
362 -
363 - k = k + 1;
3 + X = xlsread('DATA1B');
4 + X=X(1:13,1:4)
5 + [n,p] = size(X);
6 +
7 + k = 3;
8 +
9 + idx = [3 9 12];
10 + %
11 + C = X(idx,:)
12 + %
13 + temp = zeros(n,1);
14 +
15 + it=0
16 + while 1,
17 + for i =1:n
18 + for l = 1:k
19 + sum=0;
20 + for j = 1:p
21 + sum=sum+(X(i,j)-C(l,j))^2;
22 + end
23 + d(i,l)=sqrt(sum);
24 + end
364 25 end
365 - end
366 -
367 - % Merubah RGB ke Greyscale
368 - GYS1 = 0.299 * mat_gambar1(:,1) + 0.587 * mat_gambar1(:,2) + 0.114 * mat_gambar1(:,3);
369 - GYS2 = 0.299 * mat_gambar2(:,1) + 0.587 * mat_gambar2(:,2) + 0.114 * mat_gambar2(:,3);
370 - GYS3 = 0.299 * mat_gambar3(:,1) + 0.587 * mat_gambar3(:,2) + 0.114 * mat_gambar3(:,3);
371 - GYS4 = 0.299 * mat_gambar4(:,1) + 0.587 * mat_gambar4(:,2) + 0.114 * mat_gambar4(:,3);
372 - GYS5 = 0.299 * mat_gambar5(:,1) + 0.587 * mat_gambar5(:,2) + 0.114 * mat_gambar5(:,3);
373 - GYS6 = 0.299 * mat_gambar6(:,1) + 0.587 * mat_gambar6(:,2) + 0.114 * mat_gambar6(:,3);
374 - GYS7 = 0.299 * mat_gambar7(:,1) + 0.587 * mat_gambar7(:,2) + 0.114 * mat_gambar7(:,3);
375 - GYS8 = 0.299 * mat_gambar8(:,1) + 0.587 * mat_gambar8(:,2) + 0.114 * mat_gambar8(:,3);
376 - GYS9 = 0.299 * mat_gambar9(:,1) + 0.587 * mat_gambar9(:,2) + 0.114 * mat_gambar9(:,3);
377 - GYS10 = 0.299 * mat_gambar10(:,1) + 0.587 * mat_gambar10(:,2) + 0.114 * mat_gambar10(:,3);
378 - GYS11 = 0.299 * mat_gambar11(:,1) + 0.587 * mat_gambar11(:,2) + 0.114 * mat_gambar11(:,3);
379 - GYS12 = 0.299 * mat_gambar12(:,1) + 0.587 * mat_gambar12(:,2) + 0.114 * mat_gambar12(:,3);
380 - GYS13 = 0.299 * mat_gambar13(:,1) + 0.587 * mat_gambar13(:,2) + 0.114 * mat_gambar13(:,3);
381 - GYS14 = 0.299 * mat_gambar14(:,1) + 0.587 * mat_gambar14(:,2) + 0.114 * mat_gambar14(:,3);
382 - GYS15 = 0.299 * mat_gambar15(:,1) + 0.587 * mat_gambar15(:,2) + 0.114 * mat_gambar15(:,3);
383 - GYS16 = 0.299 * mat_gambar16(:,1) + 0.587 * mat_gambar16(:,2) + 0.114 * mat_gambar16(:,3);
384 - GYS17 = 0.299 * mat_gambar17(:,1) + 0.587 * mat_gambar17(:,2) + 0.114 * mat_gambar17(:,3);
385 - GYS18 = 0.299 * mat_gambar18(:,1) + 0.587 * mat_gambar18(:,2) + 0.114 * mat_gambar18(:,3);
386 - GYS19 = 0.299 * mat_gambar19(:,1) + 0.587 * mat_gambar19(:,2) + 0.114 * mat_gambar19(:,3);
387 - GYS20 = 0.299 * mat_gambar20(:,1) + 0.587 * mat_gambar20(:,2) + 0.114 * mat_gambar20(:,3);
388 - GYS21 = 0.299 * mat_gambar21(:,1) + 0.587 * mat_gambar21(:,2) + 0.114 * mat_gambar21(:,3);
389 - GYS22 = 0.299 * mat_gambar22(:,1) + 0.587 * mat_gambar22(:,2) + 0.114 * mat_gambar22(:,3);
390 - GYS23 = 0.299 * mat_gambar23(:,1) + 0.587 * mat_gambar23(:,2) + 0.114 * mat_gambar23(:,3);
391 - GYS24 = 0.299 * mat_gambar24(:,1) + 0.587 * mat_gambar24(:,2) + 0.114 * mat_gambar24(:,3);
392 - GYS25 = 0.299 * mat_gambar25(:,1) + 0.587 * mat_gambar25(:,2) + 0.114 * mat_gambar25(:,3);
393 - GYS26 = 0.299 * mat_gambar26(:,1) + 0.587 * mat_gambar26(:,2) + 0.114 * mat_gambar26(:,3);
394 - GYS27 = 0.299 * mat_gambar27(:,1) + 0.587 * mat_gambar27(:,2) + 0.114 * mat_gambar27(:,3);
395 - GYS28 = 0.299 * mat_gambar28(:,1) + 0.587 * mat_gambar28(:,2) + 0.114 * mat_gambar28(:,3);
396 - GYS29 = 0.299 * mat_gambar29(:,1) + 0.587 * mat_gambar29(:,2) + 0.114 * mat_gambar29(:,3);
397 - GYS30 = 0.299 * mat_gambar30(:,1) + 0.587 * mat_gambar30(:,2) + 0.114 * mat_gambar30(:,3);
398 -
399 - GYS1 = GYS1';
400 - GYS2 = GYS2';
401 - GYS3 = GYS3';
402 - GYS4 = GYS4';
403 - GYS5 = GYS5';
404 - GYS6 = GYS6';
405 - GYS7 = GYS7';
406 - GYS8 = GYS8';
407 - GYS9 = GYS9';
408 - GYS10 = GYS10';
409 - GYS11 = GYS11';
410 - GYS12 = GYS12';
411 - GYS13 = GYS13';
412 - GYS14 = GYS14';
413 - GYS15 = GYS15';
414 - GYS16 = GYS16';
415 - GYS17 = GYS17';
416 - GYS18 = GYS18';
417 - GYS19 = GYS19';
418 - GYS20 = GYS20';
419 - GYS21 = GYS21';
420 - GYS22 = GYS22';
421 - GYS23 = GYS23';
422 - GYS24 = GYS24';
423 - GYS25 = GYS25';
424 - GYS26 = GYS26';
425 - GYS27 = GYS27';
426 - GYS28 = GYS28';
427 - GYS29 = GYS29';
428 - GYS30 = GYS30';
429 -
430 - DataGYS = [GYS1; GYS2; GYS3; GYS4; GYS5; GYS6; GYS7; GYS8; GYS9; GYS10; GYS11; GYS12; GYS13; GYS14; GYS15; GYS16; GYS17; GYS18; GYS19; GYS20; GYS21; GYS22; GYS23; GYS24; GYS25; GYS26; GYS27; GYS28; GYS29; GYS30;];
431 -
432 - [n,p] = size(DataGYS);
433 - Xrata = mean(DataGYS);
434 -
435 - for i = 1:n
436 - Z(i, :) = DataGYS(i, :) - Xrata;
437 - end
438 -
439 - S = cov(DataGYS);
440 -
441 - for i = 1:n
442 - for j = 1:p
443 - Zr(i,j) = Z(i,j) / sqrt(S(j,j)); % Zr adalah data hasil normalisasi
26 + [z,g]=min(d,[],2);
27 + if(g==temp)
28 + break;
29 + else
30 + temp = g;
31 + end
32 + for i=1:k
33 + f=find(g==i);
34 + if f
35 + C(i,:)=mean(X(find(g==i),:),1);
36 + end
444 37 end
38 + it=it+1;
445 39 end
446 40
447 - Zcov = cov(Zr);
448 -
449 - [VA, DA] = eig(Zcov);
450 41
451 - m = 1
452 - for i = p:-1:1
453 - DA_urut(m,m) = DA(i,i);
454 - VA_urut(m,:) = VA(i,:);
455 - m = m+1;
42 + y = [X,g];
43 + for i=1:n
44 + no(i) = norm(X(i,:));
456 45 end
457 -
458 - for i = 1:p
459 - eValue(i,1) = DA_urut(i,i);
46 + y1 = [(1:n)', no',g];
47 +
48 + k1 = X(find(g==1),:)
49 + k2 = X(find(g==2),:)
50 + k3 = X(find(g==3),:)
51 + [n1,p1] = size(k1);
52 + [n2,p2] = size(k2);
53 + [n3,p3] = size(k3);
54 + for i=1:n1
55 + norm1(i) = norm(k1(i,:));
460 56 end
461 57
462 - Total = sum(eValue)
58 + x1 = [k1 norm1']
463 59
464 - PK = 0;
465 - komponen = 0;%jumlah komponen utama yang dipertahankan
466 -
467 - for j = 1:p
468 - proporsiValue(j,:) = eValue(j,1) / Total;%mengukur seberapa besar kontribusi eigenvalue ke-j terhadap varians total data.
469 - if(PK < 0.9) % Nilai PK tergantung peneliti --> 0.8
470 - PK = PK + proporsiValue(j, :);
471 - komponen = komponen + 1;
472 - end
60 + for i=1:n2
61 + norm2(i) = norm(k2(i,:));
473 62 end
474 63
475 - VA_Komponen = VA_urut(:,1:komponen)
64 + x2 = [k2 norm2']
476 65
477 - W = Z * VA_Komponen
478 -
479 - plot3(W(:,1), W(:,2), W(:,3), '*')
66 + for i=1:n3
67 + norm3(i) = norm(k3(i,:));
68 + end
480 69
481 - grid on
70 + x3 = [k3 norm3']
71 +
72 + cov1 = cov(k1)
73 + cov2 = cov(k2)
74 + cov3 = cov(k3)
75 + det1 = det(cov1)
76 + det2 = det(cov2)
77 + det3 = det(cov3)
78 + c1 = y1(find(g==1),:);
79 + c2 = y1(find(g==2),:);
80 + c3 = y1(find(g==3),:);
81 +
82 + plot(c1(:,1),norm1, 'r*', c2(:,1),norm2, 'b*', c3(:,1),norm3, 'g*')
83 + hold on
84 + grid on
85 + legend({'Cluster 1','Cluster 2', 'Cluster 3'},'Location','northeast')
86 + title('Norm Distance Plot');

moepoi's Avatar moepoi ревизий этого фрагмента 1697210782. К ревизии

2 files changed, 498 insertions, 14 deletions

1.m

@@ -1 +1,481 @@
1 - .
1 + clear; clc;
2 +
3 + % Load image (Type : UINT8)
4 + gambar1 = imread('Banana/1.jpg');
5 + gambar2 = imread('Banana/2.jpg');
6 + gambar3 = imread('Banana/3.jpg');
7 + gambar4 = imread('Banana/4.jpg');
8 + gambar5 = imread('Banana/5.jpg');
9 + gambar6 = imread('Banana/6.jpg');
10 + gambar7 = imread('Banana/7.jpg');
11 + gambar8 = imread('Banana/8.jpg');
12 + gambar9 = imread('Banana/9.jpg');
13 + gambar10 = imread('Banana/10.jpg');
14 + gambar11 = imread('Kiwi/1.jpg');
15 + gambar12 = imread('Kiwi/2.jpg');
16 + gambar13 = imread('Kiwi/3.jpg');
17 + gambar14 = imread('Kiwi/4.jpg');
18 + gambar15 = imread('Kiwi/5.jpg');
19 + gambar16 = imread('Kiwi/6.jpg');
20 + gambar17 = imread('Kiwi/7.jpg');
21 + gambar18 = imread('Kiwi/8.jpg');
22 + gambar19 = imread('Kiwi/9.jpg');
23 + gambar20 = imread('Kiwi/10.jpg');
24 + gambar21 = imread('Orange/1.jpg');
25 + gambar22 = imread('Orange/2.jpg');
26 + gambar23 = imread('Orange/3.jpg');
27 + gambar24 = imread('Orange/4.jpg');
28 + gambar25 = imread('Orange/5.jpg');
29 + gambar26 = imread('Orange/6.jpg');
30 + gambar27 = imread('Orange/7.jpg');
31 + gambar28 = imread('Orange/8.jpg');
32 + gambar29 = imread('Orange/9.jpg');
33 + gambar30 = imread('Orange/10.jpg');
34 +
35 + % Konversi UINT8 menjadi double agar dapat di operasikan komputasinya
36 + gambar1 = double(gambar1);
37 + gambar2 = double(gambar2);
38 + gambar3 = double(gambar3);
39 + gambar4 = double(gambar4);
40 + gambar5 = double(gambar5);
41 + gambar6 = double(gambar6);
42 + gambar7 = double(gambar7);
43 + gambar8 = double(gambar8);
44 + gambar9 = double(gambar9);
45 + gambar10 = double(gambar10);
46 + gambar11 = double(gambar11);
47 + gambar12 = double(gambar12);
48 + gambar13 = double(gambar13);
49 + gambar14 = double(gambar14);
50 + gambar15 = double(gambar15);
51 + gambar16 = double(gambar16);
52 + gambar17 = double(gambar17);
53 + gambar18 = double(gambar18);
54 + gambar19 = double(gambar19);
55 + gambar20 = double(gambar20);
56 + gambar21 = double(gambar21);
57 + gambar22 = double(gambar22);
58 + gambar23 = double(gambar23);
59 + gambar24 = double(gambar24);
60 + gambar25 = double(gambar25);
61 + gambar26 = double(gambar26);
62 + gambar27 = double(gambar27);
63 + gambar28 = double(gambar28);
64 + gambar29 = double(gambar29);
65 + gambar30 = double(gambar30);
66 +
67 + % 1,2,3 itu layer, RGB itu warnanya
68 + gambar1R = gambar1(:,:,1); % layer 1
69 + gambar1G = gambar1(:,:,2); % layer 2
70 + gambar1B = gambar1(:,:,3); % layer 3
71 +
72 + gambar2R = gambar2(:,:,1);
73 + gambar2G = gambar2(:,:,2);
74 + gambar2B = gambar2(:,:,3);
75 +
76 + gambar3R = gambar3(:,:,1);
77 + gambar3G = gambar3(:,:,2);
78 + gambar3B = gambar3(:,:,3);
79 +
80 + gambar4R = gambar4(:,:,1);
81 + gambar4G = gambar4(:,:,2);
82 + gambar4B = gambar4(:,:,3);
83 +
84 + gambar5R = gambar5(:,:,1);
85 + gambar5G = gambar5(:,:,2);
86 + gambar5B = gambar5(:,:,3);
87 +
88 + gambar6R = gambar6(:,:,1);
89 + gambar6G = gambar6(:,:,2);
90 + gambar6B = gambar6(:,:,3);
91 +
92 + gambar7R = gambar7(:,:,1);
93 + gambar7G = gambar7(:,:,2);
94 + gambar7B = gambar7(:,:,3);
95 +
96 + gambar8R = gambar8(:,:,1);
97 + gambar8G = gambar8(:,:,2);
98 + gambar8B = gambar8(:,:,3);
99 +
100 + gambar9R = gambar9(:,:,1);
101 + gambar9G = gambar9(:,:,2);
102 + gambar9B = gambar9(:,:,3);
103 +
104 + gambar10R = gambar10(:,:,1);
105 + gambar10G = gambar10(:,:,2);
106 + gambar10B = gambar10(:,:,3);
107 +
108 + gambar11R = gambar11(:,:,1);
109 + gambar11G = gambar11(:,:,2);
110 + gambar11B = gambar11(:,:,3);
111 +
112 + gambar12R = gambar12(:,:,1);
113 + gambar12G = gambar12(:,:,2);
114 + gambar12B = gambar12(:,:,3);
115 +
116 + gambar13R = gambar13(:,:,1);
117 + gambar13G = gambar13(:,:,2);
118 + gambar13B = gambar13(:,:,3);
119 +
120 + gambar14R = gambar14(:,:,1);
121 + gambar14G = gambar14(:,:,2);
122 + gambar14B = gambar14(:,:,3);
123 +
124 + gambar15R = gambar15(:,:,1);
125 + gambar15G = gambar15(:,:,2);
126 + gambar15B = gambar15(:,:,3);
127 +
128 + gambar16R = gambar16(:,:,1);
129 + gambar16G = gambar16(:,:,2);
130 + gambar16B = gambar16(:,:,3);
131 +
132 + gambar17R = gambar17(:,:,1);
133 + gambar17G = gambar17(:,:,2);
134 + gambar17B = gambar17(:,:,3);
135 +
136 + gambar18R = gambar18(:,:,1);
137 + gambar18G = gambar18(:,:,2);
138 + gambar18B = gambar18(:,:,3);
139 +
140 + gambar19R = gambar19(:,:,1);
141 + gambar19G = gambar19(:,:,2);
142 + gambar19B = gambar19(:,:,3);
143 +
144 + gambar20R = gambar20(:,:,1);
145 + gambar20G = gambar20(:,:,2);
146 + gambar20B = gambar20(:,:,3);
147 +
148 + gambar21R = gambar21(:,:,1);
149 + gambar21G = gambar21(:,:,2);
150 + gambar21B = gambar21(:,:,3);
151 +
152 + gambar22R = gambar22(:,:,1);
153 + gambar22G = gambar22(:,:,2);
154 + gambar22B = gambar22(:,:,3);
155 +
156 + gambar23R = gambar23(:,:,1);
157 + gambar23G = gambar23(:,:,2);
158 + gambar23B = gambar23(:,:,3);
159 +
160 + gambar24R = gambar24(:,:,1);
161 + gambar24G = gambar24(:,:,2);
162 + gambar24B = gambar24(:,:,3);
163 +
164 + gambar25R = gambar25(:,:,1);
165 + gambar25G = gambar25(:,:,2);
166 + gambar25B = gambar25(:,:,3);
167 +
168 + gambar26R = gambar26(:,:,1);
169 + gambar26G = gambar26(:,:,2);
170 + gambar26B = gambar26(:,:,3);
171 +
172 + gambar27R = gambar27(:,:,1);
173 + gambar27G = gambar27(:,:,2);
174 + gambar27B = gambar27(:,:,3);
175 +
176 + gambar28R = gambar28(:,:,1);
177 + gambar28G = gambar28(:,:,2);
178 + gambar28B = gambar28(:,:,3);
179 +
180 + gambar29R = gambar29(:,:,1);
181 + gambar29G = gambar29(:,:,2);
182 + gambar29B = gambar29(:,:,3);
183 +
184 + gambar30R = gambar30(:,:,1);
185 + gambar30G = gambar30(:,:,2);
186 + gambar30B = gambar30(:,:,3);
187 +
188 + [n,p] = size(gambar1R);
189 +
190 + k = 1;
191 + for i=1:n
192 + for j=1:p
193 + vgambar1R(k,1) = gambar1R(i,j);
194 + vgambar1G(k,1) = gambar1G(i,j);
195 + vgambar1B(k,1) = gambar1B(i,j);
196 + mat_gambar1 = [vgambar1R, vgambar1G, vgambar1B];
197 +
198 +
199 + vgambar2R(k,1) = gambar2R(i,j);
200 + vgambar2G(k,1) = gambar2G(i,j);
201 + vgambar2B(k,1) = gambar2B(i,j);
202 + mat_gambar2 = [vgambar2R, vgambar2G, vgambar2B];
203 +
204 +
205 + vgambar3R(k,1) = gambar3R(i,j);
206 + vgambar3G(k,1) = gambar3G(i,j);
207 + vgambar3B(k,1) = gambar3B(i,j);
208 + mat_gambar3 = [vgambar3R, vgambar3G, vgambar3B];
209 +
210 +
211 + vgambar4R(k,1) = gambar4R(i,j);
212 + vgambar4G(k,1) = gambar4G(i,j);
213 + vgambar4B(k,1) = gambar4B(i,j);
214 + mat_gambar4 = [vgambar4R, vgambar4G, vgambar4B];
215 +
216 +
217 + vgambar5R(k,1) = gambar5R(i,j);
218 + vgambar5G(k,1) = gambar5G(i,j);
219 + vgambar5B(k,1) = gambar5B(i,j);
220 + mat_gambar5 = [vgambar5R, vgambar5G, vgambar5B];
221 +
222 +
223 + vgambar6R(k,1) = gambar6R(i,j);
224 + vgambar6G(k,1) = gambar6G(i,j);
225 + vgambar6B(k,1) = gambar6B(i,j);
226 + mat_gambar6 = [vgambar6R, vgambar6G, vgambar6B];
227 +
228 +
229 + vgambar7R(k,1) = gambar7R(i,j);
230 + vgambar7G(k,1) = gambar7G(i,j);
231 + vgambar7B(k,1) = gambar7B(i,j);
232 + mat_gambar7 = [vgambar7R, vgambar7G, vgambar7B];
233 +
234 +
235 + vgambar8R(k,1) = gambar8R(i,j);
236 + vgambar8G(k,1) = gambar8G(i,j);
237 + vgambar8B(k,1) = gambar8B(i,j);
238 + mat_gambar8 = [vgambar8R, vgambar8G, vgambar8B];
239 +
240 +
241 + vgambar9R(k,1) = gambar9R(i,j);
242 + vgambar9G(k,1) = gambar9G(i,j);
243 + vgambar9B(k,1) = gambar9B(i,j);
244 + mat_gambar9 = [vgambar9R, vgambar9G, vgambar9B];
245 +
246 +
247 + vgambar10R(k,1) = gambar10R(i,j);
248 + vgambar10G(k,1) = gambar10G(i,j);
249 + vgambar10B(k,1) = gambar10B(i,j);
250 + mat_gambar10 = [vgambar10R, vgambar10G, vgambar10B];
251 +
252 +
253 + vgambar11R(k,1) = gambar11R(i,j);
254 + vgambar11G(k,1) = gambar11G(i,j);
255 + vgambar11B(k,1) = gambar11B(i,j);
256 + mat_gambar11 = [vgambar11R, vgambar11G, vgambar11B];
257 +
258 +
259 + vgambar12R(k,1) = gambar12R(i,j);
260 + vgambar12G(k,1) = gambar12G(i,j);
261 + vgambar12B(k,1) = gambar12B(i,j);
262 + mat_gambar12 = [vgambar12R, vgambar12G, vgambar12B];
263 +
264 +
265 + vgambar13R(k,1) = gambar13R(i,j);
266 + vgambar13G(k,1) = gambar13G(i,j);
267 + vgambar13B(k,1) = gambar13B(i,j);
268 + mat_gambar13 = [vgambar13R, vgambar13G, vgambar13B];
269 +
270 +
271 + vgambar14R(k,1) = gambar14R(i,j);
272 + vgambar14G(k,1) = gambar14G(i,j);
273 + vgambar14B(k,1) = gambar14B(i,j);
274 + mat_gambar14 = [vgambar14R, vgambar14G, vgambar14B];
275 +
276 +
277 + vgambar15R(k,1) = gambar15R(i,j);
278 + vgambar15G(k,1) = gambar15G(i,j);
279 + vgambar15B(k,1) = gambar15B(i,j);
280 + mat_gambar15 = [vgambar15R, vgambar15G, vgambar15B];
281 +
282 +
283 + vgambar16R(k,1) = gambar16R(i,j);
284 + vgambar16G(k,1) = gambar16G(i,j);
285 + vgambar16B(k,1) = gambar16B(i,j);
286 + mat_gambar16 = [vgambar16R, vgambar16G, vgambar16B];
287 +
288 +
289 + vgambar17R(k,1) = gambar17R(i,j);
290 + vgambar17G(k,1) = gambar17G(i,j);
291 + vgambar17B(k,1) = gambar17B(i,j);
292 + mat_gambar17 = [vgambar17R, vgambar17G, vgambar17B];
293 +
294 +
295 + vgambar18R(k,1) = gambar18R(i,j);
296 + vgambar18G(k,1) = gambar18G(i,j);
297 + vgambar18B(k,1) = gambar18B(i,j);
298 + mat_gambar18 = [vgambar18R, vgambar18G, vgambar18B];
299 +
300 +
301 + vgambar19R(k,1) = gambar19R(i,j);
302 + vgambar19G(k,1) = gambar19G(i,j);
303 + vgambar19B(k,1) = gambar19B(i,j);
304 + mat_gambar19 = [vgambar19R, vgambar19G, vgambar19B];
305 +
306 +
307 + vgambar20R(k,1) = gambar20R(i,j);
308 + vgambar20G(k,1) = gambar20G(i,j);
309 + vgambar20B(k,1) = gambar20B(i,j);
310 + mat_gambar20 = [vgambar20R, vgambar20G, vgambar20B];
311 +
312 +
313 + vgambar21R(k,1) = gambar21R(i,j);
314 + vgambar21G(k,1) = gambar21G(i,j);
315 + vgambar21B(k,1) = gambar21B(i,j);
316 + mat_gambar21 = [vgambar21R, vgambar21G, vgambar21B];
317 +
318 + vgambar22R(k,1) = gambar22R(i,j);
319 + vgambar22G(k,1) = gambar22G(i,j);
320 + vgambar22B(k,1) = gambar22B(i,j);
321 + mat_gambar22 = [vgambar22R, vgambar22G, vgambar22B];
322 +
323 + vgambar23R(k,1) = gambar23R(i,j);
324 + vgambar23G(k,1) = gambar23G(i,j);
325 + vgambar23B(k,1) = gambar23B(i,j);
326 + mat_gambar23 = [vgambar23R, vgambar23G, vgambar23B];
327 +
328 + vgambar24R(k,1) = gambar24R(i,j);
329 + vgambar24G(k,1) = gambar24G(i,j);
330 + vgambar24B(k,1) = gambar24B(i,j);
331 + mat_gambar24 = [vgambar24R, vgambar24G, vgambar24B];
332 +
333 + vgambar25R(k,1) = gambar25R(i,j);
334 + vgambar25G(k,1) = gambar25G(i,j);
335 + vgambar25B(k,1) = gambar25B(i,j);
336 + mat_gambar25 = [vgambar25R, vgambar25G, vgambar25B];
337 +
338 + vgambar26R(k,1) = gambar26R(i,j);
339 + vgambar26G(k,1) = gambar26G(i,j);
340 + vgambar26B(k,1) = gambar26B(i,j);
341 + mat_gambar26 = [vgambar26R, vgambar26G, vgambar26B];
342 +
343 + vgambar27R(k,1) = gambar27R(i,j);
344 + vgambar27G(k,1) = gambar27G(i,j);
345 + vgambar27B(k,1) = gambar27B(i,j);
346 + mat_gambar27 = [vgambar27R, vgambar27G, vgambar27B];
347 +
348 + vgambar28R(k,1) = gambar28R(i,j);
349 + vgambar28G(k,1) = gambar28G(i,j);
350 + vgambar28B(k,1) = gambar28B(i,j);
351 + mat_gambar28 = [vgambar28R, vgambar28G, vgambar28B];
352 +
353 + vgambar29R(k,1) = gambar29R(i,j);
354 + vgambar29G(k,1) = gambar29G(i,j);
355 + vgambar29B(k,1) = gambar29B(i,j);
356 + mat_gambar29 = [vgambar29R, vgambar29G, vgambar29B];
357 +
358 + vgambar30R(k,1) = gambar30R(i,j);
359 + vgambar30G(k,1) = gambar30G(i,j);
360 + vgambar30B(k,1) = gambar30B(i,j);
361 + mat_gambar30 = [vgambar30R, vgambar30G, vgambar30B];
362 +
363 + k = k + 1;
364 + end
365 + end
366 +
367 + % Merubah RGB ke Greyscale
368 + GYS1 = 0.299 * mat_gambar1(:,1) + 0.587 * mat_gambar1(:,2) + 0.114 * mat_gambar1(:,3);
369 + GYS2 = 0.299 * mat_gambar2(:,1) + 0.587 * mat_gambar2(:,2) + 0.114 * mat_gambar2(:,3);
370 + GYS3 = 0.299 * mat_gambar3(:,1) + 0.587 * mat_gambar3(:,2) + 0.114 * mat_gambar3(:,3);
371 + GYS4 = 0.299 * mat_gambar4(:,1) + 0.587 * mat_gambar4(:,2) + 0.114 * mat_gambar4(:,3);
372 + GYS5 = 0.299 * mat_gambar5(:,1) + 0.587 * mat_gambar5(:,2) + 0.114 * mat_gambar5(:,3);
373 + GYS6 = 0.299 * mat_gambar6(:,1) + 0.587 * mat_gambar6(:,2) + 0.114 * mat_gambar6(:,3);
374 + GYS7 = 0.299 * mat_gambar7(:,1) + 0.587 * mat_gambar7(:,2) + 0.114 * mat_gambar7(:,3);
375 + GYS8 = 0.299 * mat_gambar8(:,1) + 0.587 * mat_gambar8(:,2) + 0.114 * mat_gambar8(:,3);
376 + GYS9 = 0.299 * mat_gambar9(:,1) + 0.587 * mat_gambar9(:,2) + 0.114 * mat_gambar9(:,3);
377 + GYS10 = 0.299 * mat_gambar10(:,1) + 0.587 * mat_gambar10(:,2) + 0.114 * mat_gambar10(:,3);
378 + GYS11 = 0.299 * mat_gambar11(:,1) + 0.587 * mat_gambar11(:,2) + 0.114 * mat_gambar11(:,3);
379 + GYS12 = 0.299 * mat_gambar12(:,1) + 0.587 * mat_gambar12(:,2) + 0.114 * mat_gambar12(:,3);
380 + GYS13 = 0.299 * mat_gambar13(:,1) + 0.587 * mat_gambar13(:,2) + 0.114 * mat_gambar13(:,3);
381 + GYS14 = 0.299 * mat_gambar14(:,1) + 0.587 * mat_gambar14(:,2) + 0.114 * mat_gambar14(:,3);
382 + GYS15 = 0.299 * mat_gambar15(:,1) + 0.587 * mat_gambar15(:,2) + 0.114 * mat_gambar15(:,3);
383 + GYS16 = 0.299 * mat_gambar16(:,1) + 0.587 * mat_gambar16(:,2) + 0.114 * mat_gambar16(:,3);
384 + GYS17 = 0.299 * mat_gambar17(:,1) + 0.587 * mat_gambar17(:,2) + 0.114 * mat_gambar17(:,3);
385 + GYS18 = 0.299 * mat_gambar18(:,1) + 0.587 * mat_gambar18(:,2) + 0.114 * mat_gambar18(:,3);
386 + GYS19 = 0.299 * mat_gambar19(:,1) + 0.587 * mat_gambar19(:,2) + 0.114 * mat_gambar19(:,3);
387 + GYS20 = 0.299 * mat_gambar20(:,1) + 0.587 * mat_gambar20(:,2) + 0.114 * mat_gambar20(:,3);
388 + GYS21 = 0.299 * mat_gambar21(:,1) + 0.587 * mat_gambar21(:,2) + 0.114 * mat_gambar21(:,3);
389 + GYS22 = 0.299 * mat_gambar22(:,1) + 0.587 * mat_gambar22(:,2) + 0.114 * mat_gambar22(:,3);
390 + GYS23 = 0.299 * mat_gambar23(:,1) + 0.587 * mat_gambar23(:,2) + 0.114 * mat_gambar23(:,3);
391 + GYS24 = 0.299 * mat_gambar24(:,1) + 0.587 * mat_gambar24(:,2) + 0.114 * mat_gambar24(:,3);
392 + GYS25 = 0.299 * mat_gambar25(:,1) + 0.587 * mat_gambar25(:,2) + 0.114 * mat_gambar25(:,3);
393 + GYS26 = 0.299 * mat_gambar26(:,1) + 0.587 * mat_gambar26(:,2) + 0.114 * mat_gambar26(:,3);
394 + GYS27 = 0.299 * mat_gambar27(:,1) + 0.587 * mat_gambar27(:,2) + 0.114 * mat_gambar27(:,3);
395 + GYS28 = 0.299 * mat_gambar28(:,1) + 0.587 * mat_gambar28(:,2) + 0.114 * mat_gambar28(:,3);
396 + GYS29 = 0.299 * mat_gambar29(:,1) + 0.587 * mat_gambar29(:,2) + 0.114 * mat_gambar29(:,3);
397 + GYS30 = 0.299 * mat_gambar30(:,1) + 0.587 * mat_gambar30(:,2) + 0.114 * mat_gambar30(:,3);
398 +
399 + GYS1 = GYS1';
400 + GYS2 = GYS2';
401 + GYS3 = GYS3';
402 + GYS4 = GYS4';
403 + GYS5 = GYS5';
404 + GYS6 = GYS6';
405 + GYS7 = GYS7';
406 + GYS8 = GYS8';
407 + GYS9 = GYS9';
408 + GYS10 = GYS10';
409 + GYS11 = GYS11';
410 + GYS12 = GYS12';
411 + GYS13 = GYS13';
412 + GYS14 = GYS14';
413 + GYS15 = GYS15';
414 + GYS16 = GYS16';
415 + GYS17 = GYS17';
416 + GYS18 = GYS18';
417 + GYS19 = GYS19';
418 + GYS20 = GYS20';
419 + GYS21 = GYS21';
420 + GYS22 = GYS22';
421 + GYS23 = GYS23';
422 + GYS24 = GYS24';
423 + GYS25 = GYS25';
424 + GYS26 = GYS26';
425 + GYS27 = GYS27';
426 + GYS28 = GYS28';
427 + GYS29 = GYS29';
428 + GYS30 = GYS30';
429 +
430 + DataGYS = [GYS1; GYS2; GYS3; GYS4; GYS5; GYS6; GYS7; GYS8; GYS9; GYS10; GYS11; GYS12; GYS13; GYS14; GYS15; GYS16; GYS17; GYS18; GYS19; GYS20; GYS21; GYS22; GYS23; GYS24; GYS25; GYS26; GYS27; GYS28; GYS29; GYS30;];
431 +
432 + [n,p] = size(DataGYS);
433 + Xrata = mean(DataGYS);
434 +
435 + for i = 1:n
436 + Z(i, :) = DataGYS(i, :) - Xrata;
437 + end
438 +
439 + S = cov(DataGYS);
440 +
441 + for i = 1:n
442 + for j = 1:p
443 + Zr(i,j) = Z(i,j) / sqrt(S(j,j)); % Zr adalah data hasil normalisasi
444 + end
445 + end
446 +
447 + Zcov = cov(Zr);
448 +
449 + [VA, DA] = eig(Zcov);
450 +
451 + m = 1
452 + for i = p:-1:1
453 + DA_urut(m,m) = DA(i,i);
454 + VA_urut(m,:) = VA(i,:);
455 + m = m+1;
456 + end
457 +
458 + for i = 1:p
459 + eValue(i,1) = DA_urut(i,i);
460 + end
461 +
462 + Total = sum(eValue)
463 +
464 + PK = 0;
465 + komponen = 0;%jumlah komponen utama yang dipertahankan
466 +
467 + for j = 1:p
468 + proporsiValue(j,:) = eValue(j,1) / Total;%mengukur seberapa besar kontribusi eigenvalue ke-j terhadap varians total data.
469 + if(PK < 0.9) % Nilai PK tergantung peneliti --> 0.8
470 + PK = PK + proporsiValue(j, :);
471 + komponen = komponen + 1;
472 + end
473 + end
474 +
475 + VA_Komponen = VA_urut(:,1:komponen)
476 +
477 + W = Z * VA_Komponen
478 +
479 + plot3(W(:,1), W(:,2), W(:,3), '*')
480 +
481 + grid on

2.m

@@ -93,11 +93,12 @@ gbr28=reshape(gbr28',1,[]);
93 93 gbr29=reshape(gbr29',1,[]);
94 94 gbr30=reshape(gbr30',1,[]);
95 95
96 - X = [gbr1, gbr2, gbr3, gbr4, gbr5, gbr6, gbr7, gbr8, gbr9, gbr10, gbr11, gbr12, gbr13, gbr14, gbr15, gbr16, gbr17, gbr18, gbr19, gbr20, gbr21, gbr22, gbr23, gbr24, gbr25, gbr26, gbr27, gbr28, gbr29, gbr30];
96 + X = [gbr1; gbr2; gbr3; gbr4; gbr5; gbr6; gbr7; gbr8; gbr9; gbr10; gbr11; gbr12; gbr13; gbr14; gbr15; gbr16; gbr17; gbr18; gbr19; gbr20; gbr21; gbr22; gbr23; gbr24; gbr25; gbr26; gbr27; gbr28; gbr29; gbr30];
97 97 [n,p] = size(X);
98 - Xrata = mean(X)
98 + Xrata = mean(X, 1);
99 99
100 100 %1. mengurangi setiap variable dengan rata2nya (normalisasi data)
101 + Z = zeros(size(X));
101 102 for i = 1:n
102 103 Z(i, :) = X(i, :)-Xrata;
103 104 end
@@ -106,12 +107,13 @@ end
106 107 S = cov(X); % varian
107 108
108 109 %Standardization Data
110 + Zr = zeros(size(Z));
109 111 for i = 1:n
110 112 for j = 1:p
111 113 Zr(i,j) = Z(i,j) / sqrt(S(j,j));
112 114 end
113 115 end
114 - %ZR ADALAH HASIL DARI NORMALISASI DATA X (DATA AWAL)
116 + % Zr ADALAH HASIL DARI NORMALISASI DATA X (DATA AWAL)
115 117
116 118 %2. Menghitung cov dari data yang sudah direduksi
117 119 Zcov = cov(Zr); % matrix covarian dari variable hasil normalisasi Zr
@@ -123,38 +125,40 @@ Zcov = cov(Zr); % matrix covarian dari variable hasil normalisasi Zr
123 125 % Hasil library matlab eig() --> hasil = diagonal utamanya urut dari kecil ke besar
124 126 % yang diperlukan dari besar ke kecil
125 127 %mengurutkan hasil eigen (DESC)
126 - m = 1
128 + m = 1;
127 129 for i = p:-1:1
128 130 DA_urut(m,m) = DA(i,i);
129 - VA_urut(m,:) = VA(i,:);
131 + VA_urut(m,:) = VA(:,i)';
130 132 m = m+1;
131 133 end
132 134
133 135 %menghitung komponen utama
136 + eValue = zeros(p, 1);
134 137 for i = 1:p
135 138 eValue(i,1) = DA_urut(i,i);
136 139 end
137 140
138 - Total = sum(eValue)% total varians dalam data asli yang dapat dijelaskan oleh seluruh komponen utama.
141 + Total = sum(eValue); % total varians dalam data asli yang dapat dijelaskan oleh seluruh komponen utama.
139 142
140 143 % Proporsi kumulatif = mengambil data seberapa persen secara kumulatif yang
141 144 % dianggap perlu
142 145 PK = 0;
143 - komponen = 0;%jumlah komponen utama yang dipertahankan
146 + komponen = 0; % jumlah komponen utama yang dipertahankan
144 147
148 + proporsiValue = zeros(p, 1);
145 149 for j = 1:p
146 - proporsiValue(j,:) = eValue(j,1) / Total;%mengukur seberapa besar kontribusi eigenvalue ke-j terhadap varians total data.
150 + proporsiValue(j) = eValue(j,1) / Total; % mengukur seberapa besar kontribusi eigenvalue ke-j terhadap varians total data.
147 151 if(PK < 0.9) % Nilai PK tergantung peneliti --> 0.8
148 - PK = PK + proporsiValue(j, :);
152 + PK = PK + proporsiValue(j);
149 153 komponen = komponen + 1;
150 154 end
151 155 end
152 156
153 157 % Mengambil eigen vector dari komponen yang terpilih
154 - VA_Komponen = VA_urut(:,1:komponen)
158 + VA_Komponen = VA_urut(:,1:komponen);
155 159 % W = variable komponen utama / principal component variable
156 - W = Z * VA_Komponen % W ADALAH FINAL DATA YANG DISEBUTKAN DI PDF
160 + W = Zr * VA_Komponen; % W ADALAH FINAL DATA YANG DISEBUTKAN DI PDF
157 161
158 - plot3(W(:,1), W(:,2), W(:,3), '*') % PK < 0.9
159 - %plot(W(:,1), W(:,2), '*') % PK < 0.8
162 + plot3(W(:,1), W(:,2), W(:,3), '*'); % PK < 0.9
163 + %plot(W(:,1), W(:,2), '*'); % PK < 0.8
160 164 grid on

moepoi's Avatar moepoi ревизий этого фрагмента 1697210227. К ревизии

2 files changed, 161 insertions

1.m(файл создан)

@@ -0,0 +1 @@
1 + .

2.m(файл создан)

@@ -0,0 +1,160 @@
1 + clear; clc;
2 +
3 + % Get Data
4 + gbr1 = imread('images/Banana/1.jpg');
5 + gbr2 = imread('images/Banana/2.jpg');
6 + gbr3 = imread('images/Banana/3.jpg');
7 + gbr4 = imread('images/Banana/4.jpg');
8 + gbr5 = imread('images/Banana/5.jpg');
9 + gbr6 = imread('images/Banana/6.jpg');
10 + gbr7 = imread('images/Banana/7.jpg');
11 + gbr8 = imread('images/Banana/8.jpg');
12 + gbr9 = imread('images/Banana/9.jpg');
13 + gbr10 = imread('images/Banana/10.jpg');
14 + gbr11 = imread('images/Kiwi/1.jpg');
15 + gbr12 = imread('images/Kiwi/2.jpg');
16 + gbr13 = imread('images/Kiwi/3.jpg');
17 + gbr14 = imread('images/Kiwi/4.jpg');
18 + gbr15 = imread('images/Kiwi/5.jpg');
19 + gbr16 = imread('images/Kiwi/6.jpg');
20 + gbr17 = imread('images/Kiwi/7.jpg');
21 + gbr18 = imread('images/Kiwi/8.jpg');
22 + gbr19 = imread('images/Kiwi/9.jpg');
23 + gbr20 = imread('images/Kiwi/10.jpg');
24 + gbr21 = imread('images/Orange/1.jpg');
25 + gbr22 = imread('images/Orange/2.jpg');
26 + gbr23 = imread('images/Orange/3.jpg');
27 + gbr24 = imread('images/Orange/4.jpg');
28 + gbr25 = imread('images/Orange/5.jpg');
29 + gbr26 = imread('images/Orange/6.jpg');
30 + gbr27 = imread('images/Orange/7.jpg');
31 + gbr28 = imread('images/Orange/8.jpg');
32 + gbr29 = imread('images/Orange/9.jpg');
33 + gbr30 = imread('images/Orange/10.jpg');
34 + gbr1=double(rgb2gray(gbr1));
35 + gbr2=double(rgb2gray(gbr2));
36 + gbr3=double(rgb2gray(gbr3));
37 + gbr4=double(rgb2gray(gbr4));
38 + gbr5=double(rgb2gray(gbr5));
39 + gbr6=double(rgb2gray(gbr6));
40 + gbr7=double(rgb2gray(gbr7));
41 + gbr8=double(rgb2gray(gbr8));
42 + gbr9=double(rgb2gray(gbr9));
43 + gbr10=double(rgb2gray(gbr10));
44 + gbr11=double(rgb2gray(gbr11));
45 + gbr12=double(rgb2gray(gbr12));
46 + gbr13=double(rgb2gray(gbr13));
47 + gbr14=double(rgb2gray(gbr14));
48 + gbr15=double(rgb2gray(gbr15));
49 + gbr16=double(rgb2gray(gbr16));
50 + gbr17=double(rgb2gray(gbr17));
51 + gbr18=double(rgb2gray(gbr18));
52 + gbr19=double(rgb2gray(gbr19));
53 + gbr20=double(rgb2gray(gbr20));
54 + gbr21=double(rgb2gray(gbr21));
55 + gbr22=double(rgb2gray(gbr22));
56 + gbr23=double(rgb2gray(gbr23));
57 + gbr24=double(rgb2gray(gbr24));
58 + gbr25=double(rgb2gray(gbr25));
59 + gbr26=double(rgb2gray(gbr26));
60 + gbr27=double(rgb2gray(gbr27));
61 + gbr28=double(rgb2gray(gbr28));
62 + gbr29=double(rgb2gray(gbr29));
63 + gbr30=double(rgb2gray(gbr30));
64 +
65 + gbr1=reshape(gbr1',1,[]);
66 + gbr2=reshape(gbr2',1,[]);
67 + gbr3=reshape(gbr3',1,[]);
68 + gbr4=reshape(gbr4',1,[]);
69 + gbr5=reshape(gbr5',1,[]);
70 + gbr6=reshape(gbr6',1,[]);
71 + gbr7=reshape(gbr7',1,[]);
72 + gbr8=reshape(gbr8',1,[]);
73 + gbr9=reshape(gbr9',1,[]);
74 + gbr10=reshape(gbr10',1,[]);
75 + gbr11=reshape(gbr11',1,[]);
76 + gbr12=reshape(gbr12',1,[]);
77 + gbr13=reshape(gbr13',1,[]);
78 + gbr14=reshape(gbr14',1,[]);
79 + gbr15=reshape(gbr15',1,[]);
80 + gbr16=reshape(gbr16',1,[]);
81 + gbr17=reshape(gbr17',1,[]);
82 + gbr18=reshape(gbr18',1,[]);
83 + gbr19=reshape(gbr19',1,[]);
84 + gbr20=reshape(gbr20',1,[]);
85 + gbr21=reshape(gbr21',1,[]);
86 + gbr22=reshape(gbr22',1,[]);
87 + gbr23=reshape(gbr23',1,[]);
88 + gbr24=reshape(gbr24',1,[]);
89 + gbr25=reshape(gbr25',1,[]);
90 + gbr26=reshape(gbr26',1,[]);
91 + gbr27=reshape(gbr27',1,[]);
92 + gbr28=reshape(gbr28',1,[]);
93 + gbr29=reshape(gbr29',1,[]);
94 + gbr30=reshape(gbr30',1,[]);
95 +
96 + X = [gbr1, gbr2, gbr3, gbr4, gbr5, gbr6, gbr7, gbr8, gbr9, gbr10, gbr11, gbr12, gbr13, gbr14, gbr15, gbr16, gbr17, gbr18, gbr19, gbr20, gbr21, gbr22, gbr23, gbr24, gbr25, gbr26, gbr27, gbr28, gbr29, gbr30];
97 + [n,p] = size(X);
98 + Xrata = mean(X)
99 +
100 + %1. mengurangi setiap variable dengan rata2nya (normalisasi data)
101 + for i = 1:n
102 + Z(i, :) = X(i, :)-Xrata;
103 + end
104 +
105 + %Menghitung covariance matrix
106 + S = cov(X); % varian
107 +
108 + %Standardization Data
109 + for i = 1:n
110 + for j = 1:p
111 + Zr(i,j) = Z(i,j) / sqrt(S(j,j));
112 + end
113 + end
114 + %ZR ADALAH HASIL DARI NORMALISASI DATA X (DATA AWAL)
115 +
116 + %2. Menghitung cov dari data yang sudah direduksi
117 + Zcov = cov(Zr); % matrix covarian dari variable hasil normalisasi Zr
118 +
119 + %3. Menghitung eigen value dan eigen vector dari Zcov
120 + [VA, DA] = eig(Zcov); % VA = Eigen Vector ; DA = Eigen Value
121 +
122 + %4. menghitung komponen utama
123 + % Hasil library matlab eig() --> hasil = diagonal utamanya urut dari kecil ke besar
124 + % yang diperlukan dari besar ke kecil
125 + %mengurutkan hasil eigen (DESC)
126 + m = 1
127 + for i = p:-1:1
128 + DA_urut(m,m) = DA(i,i);
129 + VA_urut(m,:) = VA(i,:);
130 + m = m+1;
131 + end
132 +
133 + %menghitung komponen utama
134 + for i = 1:p
135 + eValue(i,1) = DA_urut(i,i);
136 + end
137 +
138 + Total = sum(eValue)% total varians dalam data asli yang dapat dijelaskan oleh seluruh komponen utama.
139 +
140 + % Proporsi kumulatif = mengambil data seberapa persen secara kumulatif yang
141 + % dianggap perlu
142 + PK = 0;
143 + komponen = 0;%jumlah komponen utama yang dipertahankan
144 +
145 + for j = 1:p
146 + proporsiValue(j,:) = eValue(j,1) / Total;%mengukur seberapa besar kontribusi eigenvalue ke-j terhadap varians total data.
147 + if(PK < 0.9) % Nilai PK tergantung peneliti --> 0.8
148 + PK = PK + proporsiValue(j, :);
149 + komponen = komponen + 1;
150 + end
151 + end
152 +
153 + % Mengambil eigen vector dari komponen yang terpilih
154 + VA_Komponen = VA_urut(:,1:komponen)
155 + % W = variable komponen utama / principal component variable
156 + W = Z * VA_Komponen % W ADALAH FINAL DATA YANG DISEBUTKAN DI PDF
157 +
158 + plot3(W(:,1), W(:,2), W(:,3), '*') % PK < 0.9
159 + %plot(W(:,1), W(:,2), '*') % PK < 0.8
160 + grid on
Новее Позже