boxfilter 的实现

A implementation of boxfilter



                 boxfilter 是均值滤波的一种改进。在下面这篇blog里面有介绍。

http://www.cnblogs.com/easymind223/archive/2012/11/13/2768680.html


这里我使用matlab对其进行实现。但是这里边界问题没有处理好,如果viewer有好的意见欢迎告诉我




% % *********************************************************
% code writer      : EOF
% code file        : my_boxfilter.m
% code date        : 2014.10.21
% e-mail           : jasonleaster@gmail.com
% 
% Code description :
%           Here is my implementation of boxfilter :)
%  It work correctly in the region where is not close to 
%  the end boundary but will meet problem on some where 
%  close to the image end boundary.
% *********************************************************

function Filted_Img = my_boxfilter(Image)

    if size(Image,3) ~= 1
        fprintf('ERROR Imput-Image must be ##ONE## channel image\n');
        return;
    end

    Height_Img = size(Image,1);
    Width_Img  = size(Image,2);
    
    Buffer     = zeros(1,Width_Img);
    Filted_Img = zeros(Height_Img,Width_Img);
    
    % treat this varible as a constant
    SEARCH_WIN_HEIGHT = 10;
    SEARCH_WIN_WIDTH  = 10;
    
    for row = 1: Height_Img
        for col  = 1: Width_Img
            
            sum_value = 0;
            if (row + SEARCH_WIN_HEIGHT) < Height_Img
                
                for temp = row : (row + SEARCH_WIN_HEIGHT)
                    sum_value = sum_value + Image(temp,col);
                end
            else
                
                for temp = row : Height_Img
                    sum_value = sum_value + Image(temp,col);
                end                
            end
            
            Buffer(col) = sum_value;
        end
        
        for col = 1:Width_Img
            
            if (col + SEARCH_WIN_WIDTH) < Width_Img
                
                for temp = col : col + SEARCH_WIN_WIDTH
                        Filted_Img(row,col) =  Filted_Img(row,col) + Buffer(temp);
                end
            else
                for temp = col : Width_Img
                        Filted_Img(row,col) =  Filted_Img(row,col) + Buffer(temp);
                end
            end
        end
        
    end
    
    Filted_Img = Filted_Img./(SEARCH_WIN_HEIGHT * SEARCH_WIN_WIDTH);
end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值