-
Notifications
You must be signed in to change notification settings - Fork 0
/
medfilt2new.m
executable file
·48 lines (36 loc) · 1.51 KB
/
medfilt2new.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
%{
Median filter for images that ignores the origin pixel.
author: Adam Steinberger <http://www.amsteinberger.com/>
date: June 17, 2011
updated: July 31, 2011
Copyright (C) Summer 2011 Skidmore College
This software was developed as part of a Skidmore College Summer
Faculty/Student Research Grant lead by Prof. Michael Eckmann.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
%}
% Image median filter that ignores center pixel
% image = grayscale image
% win = window size, must be positive odd integer
function result = medfilt2new(image, win)
% make a win by win pixel window filled with 1s
domain = ones(win);
% set the center pixel to 0
domain(floor(win^2/2)+1) = 0;
% n = # of pixels in neighborhood
n = sum(sum(domain));
% get middle two neighbors
num = n/2;
a = ordfilt2(image,num, domain);
b = ordfilt2(image,num+1,domain);
% return median of neighborhood
result = (double(a)+double(b))./2;
end