medfilter.m
上传用户:lcj80317
上传日期:2007-01-26
资源大小:625k
文件大小:1k
- function X = medfilter(x, m)
- % 中值滤波 原矩阵为x 使用的模板为m
- % 模板大小
- dim1 = size(m, 1);
- dim2 = size(m, 2);
- % 对边界的像素不处理 计算需要处理像素的范围
- row_min = (dim1+1) / 2;
- row_max = size(x, 1) - row_min + 1;
- col_min = (dim2+1) / 2;
- col_max = size(x, 2) - col_min + 1;
- ind_nz = find( m ~= 0);
- X = x;
- for i = row_min : row_max
- for j = col_min : col_max
- temp = x( i-(dim1-1)/2:i+(dim1-1)/2, j-(dim2-1)/2:j+(dim2-1)/2);
- element = sort( temp(ind_nz) );
- X(i, j) = element( round( size(element, 1)/2 ) );
- end
- end