【问题标题】:MATLAB function for image filtering用于图像过滤的 MATLAB 函数
【发布时间】:2017-05-28 13:36:18
【问题描述】:

我正在寻求实现我自己的 Matlab 函数,该函数可用于使用 3x3 内核计算图像过滤。

必须是这样的:function [ output_args ] = fFilter( img, mask ) 其中img 是原始图像,mask 是内核(例如B = [1,1,1;1,4,1;1,1,1]

我不应该使用 Image Processing Toolbox 中的任何内置函数。

我必须使用这个

地点:

s是过滤后的图像

p 是过滤前的图像

M 是一个内核

如果 sum(sum(M)) == 0 则 N 为 1,否则 N = sum(sum(M))

我是 MATLAB 新手,这对我来说就像是黑魔法 -_-

【问题讨论】:

    标签: matlab imagefilter


    【解决方案1】:

    这应该可以工作(未验证):

    function [ mO ] = ImageFilter( mI, mMask )
    %UNTITLED2 Summary of this function goes here
    %   Detailed explanation goes here
    
    numRows = size(mI, 1);
    numCols = size(mI, 2);
    
    % Assuming Odd number of Rows / Columns
    maskRadius = floor(siez(mMask, 1) / 2);
    
    sumMask = sum(mMask(:));
    
    if(sumMask ~= 0)
        mMask(:) = mMask / sumMask;
    end
    
    mO = zeros([numRows, numCols]);
    
    for jj = 1:numCols
        for ii = 1:numRows
            for kk = -maskRadius:maskRadius
                nn = kk + 1; %<! Mask Index
                colIdx = min(max(1, jj + kk), numCols); %<! Replicate Boundary
                for ll = -maskRadius:maskRadius
                    mm = ll + 1; %<! Mask Index
                    rowIdx = min(max(1, ii + ll), numRows); %<! Replicate Boundary
                    mO(ii, jj) = mO(ii, jj) + (mMask(mm, nn) * mI(rowIdx, colIdx));
                end
            end
        end
    end
    
    
    end
    

    以上是经典的 Correlation (Image Filtering) with Replicate Boundary Condition。

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 2021-02-27
      • 2015-07-02
      • 1970-01-01
      相关资源
      最近更新 更多