-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHW2_Task2.m
76 lines (63 loc) · 2.02 KB
/
HW2_Task2.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
% Ayse ERTAS 14035050
%kullanicidan resim almak için
[file,path] = uigetfile('*.tif;*.jpg;*.png');
% kullanici iptal ederse
if isequal(file,0)
disp('User selected Cancel');
else
disp(['Secilen resim:', fullfile(path,file)]);
%mean filtirleme icin filter size
% filter size -> 3 5 9 15
w = 11;
%sharp olmasi icin deger
k = 1;
I = imread(fullfile(path,file));
noiseDeleted=imnoise(I,'salt & pepper',0.02); % tuz ve biber gürültüsü ekle
I=medfilt2(noiseDeleted);
%Eger resim RGB ise grayscale yapmak
if size(I,3)==3
I = rgb2gray(I);
end
padding = (w-1)/2; %padding size
iPad = zeros(size(I) + padding*2); % image with padding
%Image with padding
for x=1:size(I,1)
for y=1:size(I,2)
iPad(x+padding,y+padding) = I(x,y);
end
end
%Mean filter to the image
newI = zeros(size(I));
for k=1:size(I,1)
for l=1:size(I,2)
sum=0;
for x=1:w
for y=1:w
sum = sum + iPad(k+x-1,l+y-1);
end
end
newI(k,l) = sum/(w*w);
end
end
newI = uint8(newI);
%subtracting blurred image from the original image
subI = zeros(size(I));
for x=1:size(I,1)
for y=1:size(I,2)
subI(x,y) = I(x,y) - newI(x,y);
end
end
subI = uint8(subI);
%normalization
img = ( subI - min(subI(:)) ) ./ ( max(subI(:)) - min(subI(:)) );
%sharpening the image
shrpI = zeros(size(I));
for x=1:size(I,1)
for y=1:size(I,2)
shrpI(x,y) = I(x,y) + (subI(x,y)*k);%adding image the subtracted values --> (Image + (Image - Filter))
end
end
shrpI = uint8(shrpI);
figure('Name','Homework 2 Ayse ERTAS','NumberTitle','off'),subplot(1,3,1),imshow(fullfile(path,file)),subplot(1,3,2), imshow(I),subplot(1,3,3), imshow(shrpI);
%imcontrast;
end