-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmajorityfilter.m
More file actions
33 lines (30 loc) · 901 Bytes
/
Copy pathmajorityfilter.m
File metadata and controls
33 lines (30 loc) · 901 Bytes
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
function newm = majorityfilter(img, amt)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%takes an image of classifications and smooths based on the majority within
%a neighborhood amt.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%img = imread(img);
tx = size(img,1);
ty = size(img,2);
newm = zeros(tx,ty);
clusters = max(max(img));
for i = 1:tx;
for j = 1:ty;
m = zeros(clusters,1);
for dx = -amt:amt;
for dy= -amt:amt;
if abs(tx/2 - (i + dx) + .5) < tx/2 && abs(ty/2 + .5 - (j + dy)) < ty/2;
m(img(i + dx, j + dy),1) = m(img(i + dx, j + dy), 1) + 1;
end
end
end
max2 = 1;
for it = 1 : clusters;
if m(it, 1) > m(max2,1);
max2 = it;
end
end
newm(i,j) = max2;
end
end
end