-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tugas6.m
794 lines (691 loc) · 25 KB
/
Tugas6.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
function varargout = Tugas6(varargin)
% TUGAS6 MATLAB code for Tugas6.fig
% TUGAS6, by itself, creates a new TUGAS6 or raises the existing
% singleton*.
%
% H = TUGAS6 returns the handle to a new TUGAS6 or the handle to
% the existing singleton*.
%
% TUGAS6('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TUGAS6.M with the given input arguments.
%
% TUGAS6('Property','Value',...) creates a new TUGAS6 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Tugas6_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Tugas6_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Tugas6
% Last Modified by GUIDE v2.5 04-Apr-2018 11:38:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Tugas6_OpeningFcn, ...
'gui_OutputFcn', @Tugas6_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Tugas6 is made visible.
function Tugas6_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Tugas6 (see VARARGIN)
% Choose default command line output for Tugas6
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Tugas6 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Tugas6_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in btnbrowse.
function btnbrowse_Callback(hObject, eventdata, handles)
% hObject handle to btnbrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[namafile, formatfile] = uigetfile({'*.jpg','*.png'}, 'Pilih Gambar'); % memilih gambar
global image
image = imread([formatfile, namafile]); % membaca gambar
guidata(hObject, handles);
axes(handles.axes1); % memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); % memunculkan gambar
% --- Executes on button press in btnhistogram.
function btnhistogram_Callback(hObject, eventdata, handles)
% hObject handle to btnhistogram (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
% red
Red = cat(3,R,G*0,B*0);
[rows,cols] = size(R);
% histogram array
myhist = zeros(256,1);
for k = 0 : 255
myhist(k+1) = numel(find(R == k)); % number of element dimana ada gray level = 'k'
end
figure, stem(myhist,'r');
set(gca,'XLim',[0 255])
xlabel('Gray Level')
ylabel('Number of Elements')
title('Histogram of Image')
grid on
% Green
Green = cat(3,R*0,G,B*0);
[rows,cols] = size(G);
% histogram array
myhist = zeros(256,1);
for k = 0 : 255
myhist(k+1) = numel(find(G == k)); % number of element dimana ada gray level = 'k'
end
figure, stem(myhist,'g');
set(gca,'XLim',[0 255])
xlabel('Gray Level')
ylabel('Number of Elements')
title('Histogram of Image')
grid on
% blue
Blue = cat(3,R*0,G*0,B);
[rows,cols] = size(B);
% histogram array
myhist = zeros(256,1);
for k = 0 : 255
myhist(k+1) = numel(find(B == k)); % number of element dimana ada gray level = 'k'
end
figure, stem(myhist,'b');
set(gca,'XLim',[0 255])
xlabel('Gray Level')
ylabel('Number of Elements')
title('Histogram of Image')
grid on
% --- Executes on button press in btnsembilan.
function btnsembilan_Callback(hObject, eventdata, handles)
% hObject handle to btnsembilan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[rowsi,colsi,z]= size(image);
sudut = 90;
rads = 2 * pi * sudut / 360;
% menghitung dimesi array agar gambar yang diputar akan sesuai dengan yg didalamnya
% menggunakan absolute agar bisa mendapatkan nilai positif
rowsf = ceil(rowsi * abs(cos(rads)) + colsi * abs(sin(rads)));
colsf = ceil(rowsi * abs(sin(rads)) + colsi * abs(cos(rads)));
% menentukan array dengan parameter yang dihitung dan isi array dengan angka nol
C = uint8(zeros([rowsf colsf 3 ]));
% menghitung center of original and final image
xo = ceil(rowsi / 2);
yo = ceil(colsi / 2);
midx = ceil((size(C,1)) / 2);
midy = ceil((size(C,2)) / 2);
% menghitung koordinat yang sesuai dari pixel A
% untuk setiap pixel C dan intensitasnya akan diberikan setelah diperiksa
for i = 1 : size(C,1)
for j = 1 : size(C,2)
x = (i - midx) * cos(rads) + (j - midy) * sin(rads);
y = -(i - midx) * sin(rads) +(j - midy) * cos(rads);
x = round(x) + xo;
y = round(y) + yo;
if (x >= 1 && y >= 1 && x <= size(image,1) && y <= size(image,2))
C(i,j,:) = image(x,y,:);
end
end
end
image = C;
axes(handles.axes1); % memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); % memunculkan gambar
% --- Executes on button press in btndelapan.
function btndelapan_Callback(hObject, eventdata, handles)
% hObject handle to btndelapan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[rowsi,colsi,z]= size(image);
sudut = 180;
rads = 2 * pi * sudut / 360;
% menghitung dimesi array agar gambar yang diputar akan sesuai dengan yg didalamnya
% menggunakan absolute agar bisa mendapatkan nilai positif
rowsf = ceil(rowsi * abs(cos(rads)) + colsi * abs(sin(rads)));
colsf = ceil(rowsi * abs(sin(rads)) + colsi * abs(cos(rads)));
% menentukan array dengan parameter yang dihitung dan isi array dengan angka nol
C = uint8(zeros([rowsf colsf 3 ]));
% menghitung center of original and final image
xo = ceil(rowsi / 2);
yo = ceil(colsi / 2);
midx = ceil((size(C,1)) / 2);
midy = ceil((size(C,2)) / 2);
% menghitung koordinat yang sesuai dari pixel A
% untuk setiap pixel C dan intensitasnya akan diberikan setelah diperiksa
for i = 1 : size(C,1)
for j = 1 : size(C,2)
x = (i - midx) * cos(rads) + (j - midy) * sin(rads);
y = -(i - midx) * sin(rads) +(j - midy) * cos(rads);
x = round(x) + xo;
y = round(y) + yo;
if (x >= 1 && y >= 1 && x <= size(image,1) && y <= size(image,2))
C(i,j,:) = image(x,y,:);
end
end
end
image = C;
axes(handles.axes1); % memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); % memunculkan gambar
% --- Executes on button press in btntujuh.
function btntujuh_Callback(hObject, eventdata, handles)
% hObject handle to btntujuh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[rowsi,colsi,z]= size(image);
sudut = 270;
rads = 2 * pi * sudut / 360;
% menghitung dimesi array agar gambar yang diputar akan sesuai dengan yg didalamnya
% menggunakan absolute agar bisa mendapatkan nilai positif
rowsf = ceil(rowsi * abs(cos(rads)) + colsi * abs(sin(rads)));
colsf = ceil(rowsi * abs(sin(rads)) + colsi * abs(cos(rads)));
% menentukan array dengan parameter yang dihitung dan isi array dengan angka nol
C = uint8(zeros([rowsf colsf 3 ]));
% menghitung center of original and final image
xo = ceil(rowsi / 2);
yo = ceil(colsi / 2);
midx = ceil((size(C,1)) / 2);
midy = ceil((size(C,2)) / 2);
% menghitung koordinat yang sesuai dari pixel A
% untuk setiap pixel C dan intensitasnya akan diberikan setelah diperiksa
for i = 1 : size(C,1)
for j = 1 : size(C,2)
x = (i - midx) * cos(rads) + (j - midy) * sin(rads);
y = -(i - midx) * sin(rads) +(j - midy) * cos(rads);
x = round(x) + xo;
y = round(y) + yo;
if (x >= 1 && y >= 1 && x <= size(image,1) && y <= size(image,2))
C(i,j,:) = image(x,y,:);
end
end
end
image = C;
axes(handles.axes1); % memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); % memunculkan gambar
% --- Executes on button press in btngray.
function btngray_Callback(hObject, eventdata, handles)
% hObject handle to btngray (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image
merah =image(:,:,1); % hanya berisi piksel warna merah
ijo = image(:,:,2);% hanya berisi piksel warna merah
biru = image(:,:,3); % hanya berisi piksel warna merah
%ubah warna ke abu2
abu = (0.3 * merah) + (0.5 * ijo) + (0.2 * biru);
image = abu;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnzoomin.
function btnzoomin_Callback(hObject, eventdata, handles)
% hObject handle to btnzoomin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
s = size(image);
f1 = 200;
s2=s*f1;
k=1;
l=1;
for (i=1:f1:s2)
for( j=1:f1:s2)
C(i,j)= image(k,l);
l=l+1;
end
l=1;
k=k+1;
end
for (i=1:f1:s2)
for (j=2:f1:s2-1)
C(i,j)= [C(i,j-1)+ C(i, j+1)]*0.5;
end
end
for(j=1:f1:s2)
for(i=2:f1:s2-1)
C(i,j)=[C(i-1,j)+C(i+1,j)]*0.5;
end
end
for (i=2:f1:s2-1)
for (j=2:f1:s2-1)
C(i,j)= [C(i,j-1)+ C(i, j+1)]*0.5;
end
end
image = C;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnzoomout.
function btnzoomout_Callback(hObject, eventdata, handles)
% hObject handle to btnzoomout (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
% ukuran gambar 512X512 --> 256x256 piksel
area=uint8(zeros(256,256));
% menduplikasikan data citra asli
d=zeros(512,512);
for i=1:512;
for j=1:512;
d(i,j)=image(i,j);
end
end
%kompresi dari 512x512 ke 256x256 piksel
for b_asli=1:256
for k_asli=1:256
temp=0; dummy=0;
for b_baru=1:2
for k_baru=1:2
dummyb=((b_asli-1)*2 + b_baru);
dummyk= ((k_asli-1)*2 + k_baru);
dummy=d(dummyb,dummyk);
temp=temp+dummy;
end
end
temp=round(temp/4);
area(b_asli,k_asli)=temp;
end
end
image = area;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btninverse.
function btninverse_Callback(hObject, eventdata, handles)
% hObject handle to btninverse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
nilai = uint8(image);
baris = size(nilai,1);
kolom = size(nilai,2);
for i = 1 : baris
for j = 1 : kolom
temp = 255 - nilai(i,j);
nilai(i,j) = temp;
end
end
image = nilai;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btntambah.
function btntambah_Callback(hObject, eventdata, handles)
% hObject handle to btntambah (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
nilai = uint8(image);
baris = size(nilai,1);
kolom = size(nilai,2);
for i = 1 : baris
for j = 1 : kolom
temp = nilai(i,j) + 20;
nilai(i,j) = temp;
end
end
image = nilai;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnkali.
function btnkali_Callback(hObject, eventdata, handles)
% hObject handle to btnkali (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
nilai = uint8(image);
baris = size(nilai,1);
kolom = size(nilai,2);
for i = 1 : baris
for j = 1 : kolom
temp = nilai(i,j) * 2;
nilai(i,j) = temp;
end
end
image = nilai;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnkurang.
function btnkurang_Callback(hObject, eventdata, handles)
% hObject handle to btnkurang (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
nilai = uint8(image);
baris = size(nilai,1);
kolom = size(nilai,2);
for i = 1 : baris
for j = 1 : kolom
temp = nilai(i,j) - 10;
nilai(i,j) = temp;
end
end
image = nilai;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnbagi.
function btnbagi_Callback(hObject, eventdata, handles)
% hObject handle to btnbagi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
nilai = uint8(image);
baris = size(nilai,1);
kolom = size(nilai,2);
for i = 1 : baris
for j = 1 : kolom
temp = nilai(i,j) / 2;
nilai(i,j) = temp;
end
end
image = nilai;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnhorizontal.
function btnhorizontal_Callback(hObject, eventdata, handles)
% hObject handle to btnhorizontal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
ind = 1; %inisialisasi index
for i = size(image,2) : -1 : 1
new(:, ind, :) = image(:, i, :);
ind = ind + 1;
end
image = new; %flipdim(image, 2);
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnvertikal.
function btnvertikal_Callback(hObject, eventdata, handles)
% hObject handle to btnvertikal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
ind = 1; %inisialisasi index
for i = size(image,1) : -1 : 1
new(ind, :, :) = image(i, :, :);
ind = ind + 1;
end
image = new; %flipdim(image, 1);
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btncrop.
function btncrop_Callback(hObject, eventdata, handles)
% hObject handle to btncrop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
x_TopLeft = 64;
y_TopLeft = 64;
x_BottomRight = 192;
y_BottomRight = 192;
M = x_BottomRight-x_TopLeft+1;
N = y_BottomRight-y_TopLeft+1;
for i = 1 : M
for j = 1 : N
B(i, j, :) = image(x_TopLeft+i, y_TopLeft+j, :);
end
end
image = B;
axes(handles.axes1); %memilih plotori sebagai letak gambar yang dimunculkan
imshow(image); %memunculkan gambar
% --- Executes on button press in btnhist.
function btnhist_Callback(hObject, eventdata, handles)
% hObject handle to btnhist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
% red
Red = cat(3,R,G*0,B*0);
[rows,cols] = size(R);
% histogram array
myhist = zeros(256,1);
for k = 0 : 255
myhist(k+1) = numel(find(R == k)); % number of element dimana ada gray level = 'k'
end
figure, stem(myhist,'r');
set(gca,'XLim',[0 255])
xlabel('Gray Level')
ylabel('Number of Elements')
title('Histogram of Image')
grid on
% Green
Green = cat(3,R*0,G,B*0);
[rows,cols] = size(G);
% histogram array
myhist = zeros(256,1);
for k = 0 : 255
myhist(k+1) = numel(find(G == k)); % number of element dimana ada gray level = 'k'
end
figure, stem(myhist,'g');
set(gca,'XLim',[0 255])
xlabel('Gray Level')
ylabel('Number of Elements')
title('Histogram of Image')
grid on
% blue
Blue = cat(3,R*0,G*0,B);
[rows,cols] = size(B);
% histogram array
myhist = zeros(256,1);
for k = 0 : 255
myhist(k+1) = numel(find(B == k)); % number of element dimana ada gray level = 'k'
end
figure, stem(myhist,'b');
set(gca,'XLim',[0 255])
xlabel('Gray Level')
ylabel('Number of Elements')
title('Histogram of Image')
grid on
% --- Executes on button press in btnsembilan.
function pushbutton21_Callback(hObject, eventdata, handles)
% hObject handle to btnsembilan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in btndelapan.
function pushbutton22_Callback(hObject, eventdata, handles)
% hObject handle to btndelapan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in btntujuh.
function pushbutton23_Callback(hObject, eventdata, handles)
% hObject handle to btntujuh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in btnedge.
function btnedge_Callback(hObject, eventdata, handles)
% hObject handle to btnedge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[row, coll, z] = size(image);
gambarbaru = double(image);
y = [1 1 1;
1 -8 1;
1 1 1];
for i = 2 : row - 2
for j = 2 : coll - 2
hasil = gambarbaru(i-1,j-1)*y(1,1)+gambarbaru(i,j-1)*y(2,1)...
+ gambarbaru(i+1,j-1)*y(3,1)+gambarbaru(i-1,j)*y(1,2)...
+ gambarbaru(i,j)*y(2,2)+gambarbaru(i+1,j)*y(3,2)...
+ gambarbaru(i-1,j+1)*y(1,3)+gambarbaru(i,j+1)*y(2,3)...
+ gambarbaru(i+1,j+1)*y(3,3);
gmb(i-1,j-1) = hasil;
end
end
figure
imshow(uint8(gmb));
% --- Executes on button press in btnblur.
function btnblur_Callback(hObject, eventdata, handles)
% hObject handle to btnblur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[row, coll, z] = size(image);
gambarbaru = double(image);
y = [1/9 1/9 1/9;
1/9 1/9 1/9;
1/9 1/9 1/9];
for i = 2 : row - 2
for j = 2 : coll - 2
hasil = gambarbaru(i-1,j-1,:)*y(1,1,:)+gambarbaru(i,j-1,:)*y(2,1,:)...
+ gambarbaru(i+1,j-1,:)*y(3,1,:)+gambarbaru(i-1,j,:)*y(1,2,:)...
+ gambarbaru(i,j,:)*y(2,2,:)+gambarbaru(i+1,j,:)*y(3,2,:)...
+ gambarbaru(i-1,j+1,:)*y(1,3,:)+gambarbaru(i,j+1,:)*y(2,3,:)...
+ gambarbaru(i+1,j+1,:)*y(3,3,:);
gmb(i-1,j-1,:) = hasil;
end
end
figure
imshow(uint8(gmb));
% --- Executes on button press in btnsharp.
function btnsharp_Callback(hObject, eventdata, handles)
% hObject handle to btnsharp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[row, coll, z] = size(image);
gambarbaru = double(image);
y = [0 -1 0;
-1 5 -1;
0 -1 0];
for i = 2 : row -2
for j = 2 : coll -2
hasil = gambarbaru(i-1,j-1,:)*y(1,1,:)+gambarbaru(i,j-1,:)*y(2,1,:)...
+ gambarbaru(i+1,j-1,:)*y(3,1,:)+gambarbaru(i-1,j,:)*y(1,2,:)...
+ gambarbaru(i,j,:)*y(2,2,:)+gambarbaru(i+1,j,:)*y(3,2,:)...
+ gambarbaru(i-1,j+1,:)*y(1,3,:)+gambarbaru(i,j+1,:)*y(2,3,:)...
+ gambarbaru(i+1,j+1,:)*y(3,3,:);
gmb(i-1,j-1,:) = hasil;
end
end
figure
imshow(uint8(gmb));
% --- Executes on button press in pushbutton31.
function pushbutton31_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton31 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in btnnmean.
function btnnmean_Callback(hObject, eventdata, handles)
% hObject handle to btnnmean (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[row, col, z] = size (image);
gambarbaru = double(image);
for i = 1 : row %h
for j = 1 : col %w
if (i == row)
if (i == row && j == col)
hasil = (gambarbaru(i,j,:) + 0 + 0 + 0)/4;
else
hasil = (gambarbaru(i,j,:) + gambarbaru(i,j+1,:) + 0 + 0)/4;
end
else if (j == col)
if (j == col && i == row)
hasil = (gambarbaru(i,j,:) + 0 + 0 + 0)/4;
else
hasil = (gambarbaru(i,j,:) + 0 + gambarbaru(i+1,j,:) + 0)/4;
end
else
hasil = (gambarbaru(i,j,:) + gambarbaru(i,j+1,:) + gambarbaru(i+1,j,:) + gambarbaru(i+1,j+1,:))/4;
end
end
gmb(i,j,:) = hasil;
end
end
figure
imshow(uint8(gmb));
% --- Executes on button press in btnnmedian.
function btnnmedian_Callback(hObject, eventdata, handles)
% hObject handle to btnnmedian (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[row, col, z] = size (image);
gambarbaru = double(image);
for i = 1 : row %h
for j = 1 : col %w
if (i == row)
if (i == row && j == col)
hasil = 0;
else
a = gambarbaru(i,j,:);b = gambarbaru(i,j+1,:);
g = [a b]; s = sort(g); n = s(1,1);
hasil = median([0 n]);
end
else if (j == col)
if (j == col && i == row)
hasil = median([gambarbaru(i,j,:), 0, 0, 0]);
else
a = gambarbaru(i,j,:);b = gambarbaru(i+1,j,:);
g = [a b]; s = sort(g); n = s(1,1);
hasil = median([0 n]);
end
else
hasil = median([gambarbaru(i,j,:), gambarbaru(i,j+1,:), gambarbaru(i+1,j,:), gambarbaru(i+1,j+1,:)]);
end
end
gmb(i,j,:) = hasil;
end
end
figure
imshow(uint8(gmb));
% --- Executes on button press in btnnmodus.
function btnnmodus_Callback(hObject, eventdata, handles)
% hObject handle to btnnmodus (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[row, col, z] = size (image);
gambarbaru = double(image);
for i = 1 : row %h
for j = 1 : col %w
if (i == row)
if (i == row && j == col)
hasil = 0;
else
hasil = 0;
end
else if (j == col)
if (j == col && i == row)
hasil = mode([gambarbaru(i,j,:), 0, 0, 0]);
else
hasil = 0;
end
else
hasil = mode([gambarbaru(i,j,:), gambarbaru(i,j+1,:), gambarbaru(i+1,j,:), gambarbaru(i+1,j+1,:)]);
end
end
gmb(i,j,:) = hasil;
end
end
figure
imshow(uint8(gmb));