-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal_Project.m
More file actions
2392 lines (1861 loc) · 71.3 KB
/
Copy pathFinal_Project.m
File metadata and controls
2392 lines (1861 loc) · 71.3 KB
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
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = Final_Project(varargin)
% FINAL_PROJECT MATLAB code for Final_Project.fig
% FINAL_PROJECT, by itself, creates a new FINAL_PROJECT or raises the existing
% singleton*.
%
% H = FINAL_PROJECT returns the handle to a new FINAL_PROJECT or the handle to
% the existing singleton*.
%
% FINAL_PROJECT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FINAL_PROJECT.M with the given input arguments.
%
% FINAL_PROJECT('Property','Value',...) creates a new FINAL_PROJECT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Final_Project_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Final_Project_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 Final_Project
% Last Modified by GUIDE v2.5 27-Dec-2023 21:27:32
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Final_Project_OpeningFcn, ...
'gui_OutputFcn', @Final_Project_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 Final_Project is made visible.
function Final_Project_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 Final_Project (see VARARGIN)
% Choose default command line output for Final_Project
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Final_Project wait for user response (see UIRESUME)
% uiwait(handles.figure1);
function[mask,mask_size]=Guassian_function_2D(sigma)
% the smallest value = 0.5 any value less than 0.5 represent pixel opreation 1x1
%sigma=0.5;
N = floor(3.7*sigma-0.5);
mask_size = 2*N+1;
t = floor(mask_size/2);
x=(-t:t);
mask=zeros(mask_size,mask_size);
coef=(1/(2*pi*(sigma^2)));
for i=1:mask_size
for j=1:mask_size
mask(i,j)=coef*exp(-((x(i)^2)+(x(j)^2))/(2*(sigma^2)));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Outputs from this function are returned to the command line.
function varargout = Final_Project_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 during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
imshow('C:/Users/HP/Desktop/WhatsApp Image 2023-12-17 at 22.56.54_c47b19c4.jpg')
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.jpg*', 'Pick an Image');
name=strcat(pathname,filename);
global a;
a=imread(name);
axes(handles.axes2);
imshow(a);
setappdata(0,'a',a)
imshow(a)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.jpg*', 'Pick an Image');
name=strcat(pathname,filename);
global img2_read;
img2_read=imread(name);
axes(handles.axes3);
imshow(img2_read);
setappdata(0,'img2_read',img2_read)
imshow(img2_read)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
x=str2double(get(handles.edit1,'string'));
z=str2double(get(handles.edit5,'string'));
y=imresize(a,[x z]);
axes(handles.axes3);
imshow(y);
setappdata(0,'y',y)
imshow(y)
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
y=Gray_im(a);
axes(handles.axes3);
imshow(y);
setappdata(0,'y',y)
imshow(y)
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[r,c]=size(a);
h=zeros(1,256);
for i=1:r
for j=1:c
h(a(i,j)+1)= h(a(i,j)+1) + 1;
end
end
x=0:255;
axes(handles.axes3);
stem(x,h),title('Histo')
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
New_Max=str2double(get(handles.max,'string'));
New_Min=str2double(get(handles.min,'string'));
%--------------------------------------------------------------------------
[r,c,ch]=size(a);
New_Value=zeros(r,c,ch);
Old_Max=a(1,1,1);
Old_Min=a(1,1,1);
for k=1:ch
for i=1:r
for j=1:c
if(a(i,j,k)>=Old_Max)
Old_Max=a(i,j,k);
end
if(a(i,j,k)<=Old_Min)
Old_Min=a(i,j,k);
end
end
end
end
for k=1:ch
for i=1:r
for j=1:c
v = ((((a(i,j,k) - Old_Min)/(Old_Max - Old_Min)) * (New_Max - New_Min)) + New_Min);
if v < 0
New_Value(i,j,k) = 0;
elseif v > 255
New_Value(i,j,k) = 255;
else
New_Value(i,j,k)=v;
end
end
end
end
New_Value = uint8(New_Value);
axes(handles.axes3);
imshow(New_Value);
setappdata(0,'New_Value',New_Value)
imshow(New_Value)
function max_Callback(hObject, eventdata, handles)
% hObject handle to max (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of max as text
% str2double(get(hObject,'String')) returns contents of max as a double
% --- Executes during object creation, after setting all properties.
function max_CreateFcn(hObject, eventdata, handles)
% hObject handle to max (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function min_Callback(hObject, eventdata, handles)
% hObject handle to min (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of min as text
% str2double(get(hObject,'String')) returns contents of min as a double
% --- Executes during object creation, after setting all properties.
function min_CreateFcn(hObject, eventdata, handles)
% hObject handle to min (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton8.
f% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
global a;
% Read offset from the GUI
offset = str2double(get(handles.offset, 'string'));
% Call the Brightness function
new_image = Brightness(a, offset);
% Display the result
axes(handles.axes3);
imshow(new_image);
% Save the result to appdata for potential future use
setappdata(0, 'new_image', new_image);
function new_im = Brightness(im, offset)
[rows, cols, channels] = size(im);
% Display the original image
%figure, imshow(im), title('Original');
% Apply brightness adjustment to each pixel
for k = 1:channels
for i = 1:rows
for j = 1:cols
pixel_value = im(i, j, k) + offset;
% Ensure pixel values are in the valid range [0, 255]
if pixel_value > 255
pixel_value = 255;
elseif pixel_value < 0
pixel_value = 0;
end
im(i, j, k) = pixel_value;
end
end
end
% Return the modified image
new_im = im;
function offset_Callback(hObject, eventdata, handles)
% hObject handle to offset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of offset as text
% str2double(get(hObject,'String')) returns contents of offset as a double
% --- Executes during object creation, after setting all properties.
function offset_CreateFcn(hObject, eventdata, handles)
% hObject handle to offset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
global a;
% Read gamma from the GUI
gamma = str2double(get(handles.gamma, 'string'));
% Call the power_low function
new_image = power_low(a, gamma);
% Display the result
axes(handles.axes3);
imshow(new_image);
% Save the result to appdata for potential future use
setappdata(0, 'new_image', new_image);
function new_im = power_low(im, gamma)
% Convert the image to double for mathematical operations
image_double = im2double(im);
% Apply power-law transformation
new_im = image_double .^ gamma;
% Convert back to uint8 for displaying
new_im = uint8(new_im * 255);
function gamma_Callback(hObject, eventdata, handles)
% hObject handle to gamma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of gamma as text
% str2double(get(hObject,'String')) returns contents of gamma as a double
% --- Executes during object creation, after setting all properties.
function gamma_CreateFcn(hObject, eventdata, handles)
% hObject handle to gamma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[r,c,ch]=size(a);
pixels=r*c;%total number of pixels
num=zeros(256,1);
%Calculate the histogram
for i=1:r
for j=1:c
v=a(i,j);
num(v+1)=num(v+1)+1;
end
end
sum=0;
pc=zeros(256,1);
c=zeros(256,1);
out=zeros(256,1);
for i=1:size(num)
sum=sum+num(i);
c(i)=sum;%Calculate running sum over the histogram
pc(i)=c(i)/pixels;%Divide each value by the max value
out(i)=round(pc(i)*255);%Multiply by the new range
end
[r,c,ch]=size(a);
Hp=uint8(zeros(r,c));
for i=1:r
for j=1:c
Hp(i,j)=out(a(i,j)+1);
end
end
axes(handles.axes3);
imshow(Hp);
setappdata(0,'Hp',Hp)
imshow(Hp)
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global img2_read;
y=H_matching(a,img2_read);
axes(handles.axes3);
imshow(y);
setappdata(0,'y',y)
imshow(y),title('Histogram Matching')
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global img2_read;
[r1, c1, ch1]=size(a);
%[r2, c2, ch2]=size(im2);
img2_read = imresize(img2_read,[r1 c1]);
new_im=zeros(r1,c1,ch1);
for k=1:ch1
for i=1:r1
for j=1:c1
v=a(i,j,k)+img2_read(i,j,k);
if v>255
new_im(i,j,k)=255;
else
new_im(i,j,k)=v;
end
end
end
end
new_im = uint8(new_im);
axes(handles.axes3);
imshow(new_im);
setappdata(0,'new_im',new_im)
imshow(new_im)
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
global img2_read;
[r1, c1, ch1]=size(a);
img2_read = imresize(img2_read,[r1 c1]);
new_im=zeros(r1,c1,ch1);
for k=1:ch1
for i=1:r1
for j=1:c1
v=a(i,j,k)-img2_read(i,j,k);
if v<0
new_im(i,j,k)=abs(v);
else
new_im(i,j,k)=v;
end
end
end
end
new_im = uint8(new_im);
axes(handles.axes3);
imshow(new_im);
setappdata(0,'new_im',new_im)
imshow(new_im)
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[r,c,ch]=size(a);
New_Value=zeros(r,c,ch);
for k=1:ch
for i=1:r
for j=1:c
New_Value(i,j,k) = 255 - a(i,j,k);
end
end
end
New_Value = uint8(New_Value);
axes(handles.axes3);
imshow(New_Value);
setappdata(0,'New_Value',New_Value)
imshow(New_Value)
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
Numbit=str2double(get(handles.Numbit,'string'));
%--------------------------------------------------------------------------
[r, c, ch]=size(a);
New_img = zeros(r,c,ch);
Gray_level =power(2,Numbit); % s represent number of bits per pixel
Gap = 256/Gray_level;
Colors = Gap:Gap:256;
for k=1:ch
for i=1:r
for j=1:c
Temp=a(i,j,k)/Gap;
Index = floor(Temp);
if(Index==0)
Index=Index+1;
end
New_img(i,j,k) = Colors(Index);
end
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
function Numbit_Callback(hObject, eventdata, handles)
% hObject handle to Numbit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Numbit as text
% str2double(get(hObject,'String')) returns contents of Numbit as a double
% --- Executes during object creation, after setting all properties.
function Numbit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Numbit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton16.
% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
global a;
% Get the size from the GUI or set it as needed
n_size = str2double(get(handles.size, 'string'));
% Call the Mean_filter function
new_image = Mean_filter(a, n_size);
% Display the result
axes(handles.axes3);
imshow(new_image);
title('Mean Filter Result');
% Save the result to appdata for potential future use
setappdata(0, 'New_img', new_image);
function new_image = Mean_filter(image, mask)
[row, col, ch] = size(image);
image = padarray(image, [(mask-1)/2 (mask-1)/2], 'replicate');
new_image = zeros(row, col, ch);
for k=1:ch
for i=1:row
for j=1:col
new_image(i,j,k) = mean2(image(i:i+mask-1, j:j+mask-1, k));
end
end
end
new_image = uint8(new_image);
function size_Callback(hObject, eventdata, handles)
% hObject handle to size (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of size as text
% str2double(get(hObject,'String')) returns contents of size as a double
% --- Executes during object creation, after setting all properties.
function size_CreateFcn(hObject, eventdata, handles)
% hObject handle to size (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
global a;
% Get the mask size from the GUI or set it as needed
maskSize = str2double(get(handles.size, 'string'));
% Call the gaussianNoise function
newImage = gaussianNoise(a, maskSize);
% Display the result
axes(handles.axes3);
imshow(newImage);
title('Gaussian Noise Result');
% Save the result to appdata for potential future use
setappdata(0, 'New_img', newImage);
function New_Image = gaussianNoise(image, maskSize)
[row, col, ch] = size(image);
% Generate Gaussian noise
noisyImage = imnoise(image, 'gaussian');
% Ensure the result is of type uint8
New_Image = uint8( noisyImage);
function sigma1_Callback(hObject, eventdata, handles)
% hObject handle to sigma1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
;
% Hints: get(hObject,'String') returns contents of sigma1 as text
% str2double(get(hObject,'String')) returns contents of sigma1 as a double
% --- Executes during object creation, after setting all properties.
function sigma1_CreateFcn(hObject, eventdata, handles)
% hObject handle to sigma1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton18 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[r, c, ch]=size(a);
New_img = zeros(r,c,ch);
add=3;%number of columns and rows added
Padding_org_img = padarray(a,[add add],'replicate','both');
mask_size=7;
arr=zeros(mask_size,mask_size);
for k=1:ch
for i=1:r
for j=1:c
for fr=0:mask_size-1
for fc=0:mask_size-1
arr(fr+1,fc+1)=Padding_org_img(i+fr,j+fc,k);
end
end
sortarr=sort(arr(:));
New_img(i,j,k)=sortarr(5);
end
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
% --- Executes on button press in pushbutton19.
function pushbutton19_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton19 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[r, c, ch]=size(a);
New_img = zeros(r,c,ch);
add=1;%number of columns and rows added
Padding_org_img = padarray(a,[add add],'replicate','both');
mask_size=3;
arr=zeros(3,3);
for k=1:ch
for i=1:r
for j=1:c
for fr=0:mask_size-1
for fc=0:mask_size-1
arr(fr+1,fc+1)=Padding_org_img(i+fr,j+fc,k);
end
end
New_img(i,j,k)=max(arr(:));
end
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[r, c, ch]=size(a);
New_img = zeros(r,c,ch);
add=1;%number of columns and rows added
Padding_org_img = padarray(a,[add add],'replicate','both');
mask_size=3;
arr=zeros(3,3);
for k=1:ch
for i=1:r
for j=1:c
for fr=0:mask_size-1
for fc=0:mask_size-1
arr(fr+1,fc+1)=Padding_org_img(i+fr,j+fc,k);
end
end
New_img(i,j,k)=min(arr(:));
end
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
% --- Executes on button press in pushbutton21.
function pushbutton21_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton21 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
add=1;%number of columns and rows added
a = a(:,:,1);
Padding_org_img = padarray(a,[add add],'replicate','both');
[r, c, ch]=size(a);
New_img = zeros(r,c,ch);
for i=2:r-1
for j=2:c-1
value = Padding_org_img(i+1,j)+Padding_org_img(i-1,j)+Padding_org_img(i,j+1)+Padding_org_img(i,j-1)-4*Padding_org_img(i,j);
%Threshold
if value>20
New_img(i,j)=255;
else
New_img(i,j)=0;
end
% New_img(i,j)=value;
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
contents=cellstr(get(hObject,'String'));
pop_choice=contents{get(hObject,'Value')};
if(strcmp(pop_choice,'Edge Point Detection'))
global a;
add=1;%number of columns and rows added
a = a(:,:,1);
Padding_org_img = padarray(a,[add add],'replicate','both');
[r, c, ch]=size(a);
New_img = zeros(r,c,ch);
for i=2:r-1
for j=2:c-1
value = Padding_org_img(i+1,j)+Padding_org_img(i-1,j)+Padding_org_img(i,j+1)+Padding_org_img(i,j-1)-4*Padding_org_img(i,j);
%Threshold
if value>20
New_img(i,j)=255;
else
New_img(i,j)=0;
end
% New_img(i,j)=value;
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
elseif(strcmp(pop_choice,'Edge Detection Horizontal'))
add=1;%number of columns and rows added
a = a(:,:,1);
Padding_org_img = padarray(a,[add add],'replicate','both');
[r, c, ch]=size(Padding_org_img);
New_img = zeros(r,c,ch);
for i=2:r-1
for j=2:c-1
value =Padding_org_img(i-1,j-1)+2*Padding_org_img(i-1,j)+Padding_org_img(i-1,j+1)-Padding_org_img(i+1,j-1)-2*Padding_org_img(i+1,j)-Padding_org_img(i+1,j+1);
%Threshold
if value>30
New_img(i,j)=255;
else
New_img(i,j)=0;
end
% New_img(i,j)=value;
end
end
New_img = uint8( New_img);
axes(handles.axes3);
imshow(New_img);
setappdata(0,'New_img',New_img)
imshow(New_img)
elseif(strcmp(pop_choice,'Edge Detection Vertical'))
add=1;%number of columns and rows added
a = a(:,:,1);
Padding_org_img = padarray(a,[add add],'replicate','both');
[r, c, ch]=size(Padding_org_img);
New_img = zeros(r,c,ch);
for i=2:r-1
for j=2:c-1
value = Padding_org_img(i-1,j-1)+2*Padding_org_img(i,j-1)+Padding_org_img(i+1,j-1)-Padding_org_img(i-1,j+1)-2*Padding_org_img(i,j+1)-Padding_org_img(i+1,j+1);
%Threshold
if value>20
New_img(i,j)=255;
else
New_img(i,j)=0;
end
% New_img(i,j)=value;
end
end
New_img = uint8( New_img);
axes(handles.axes3);