下载的非本地意味着过滤器不起作用

时间:2019-02-24 20:06:52

标签: matlab filter

以下是针对非本地均值过滤器的下载算法(我对其进行了一些自定义):

function [cleared] = Non_Local_Means(I,f,t,h)

[m,n] = size(I);


% Making gaussian kernel
su=1;          %standard deviation of gaussian kernel
sm=0;          % sum of all kernel elements (for normalization)
ks= 2*f+1;     % size of kernel (same as neighborhood window size)
% Initiating kernel
ker = zeros(ks,ks);
for x=1:ks
for y=1:ks
    ab = x-f-1;   %horizontal distance of pixel from center(f+1, f+1)
    cd = y-f-1;   % vertical distance of pixel from center (f+1, f+1)
    ker(x,y) = 100*exp(((ab*ab)+(cd*cd))/(-2*(su*su)));
    sm = sm + ker(x,y);
end
end
kernel = ker ./ f;
kernel = kernel / sm;   % normalization


% Assign a clear output image
cleared = zeros(m,n);


I = padarray(I,[f,f],'symmetric');

% Now we'll calculate ouput for each pixel
for i=1:m
for j=1:n
    im = i+f;   % to compensate for shift due to padarray function
    jn= j+f;
    % neighborhood of concerned pixel (we called it similarity window)
    W1 = I(im-f:im+f , jn-f:jn+f);
    % BOundaries of similarity window for that pixel
    rmin = max(im-t, f+1);
    rmax = min(im+t, m+f);
    smin = max(jn-t, f+1);
    smax = min(jn+t, n+f);
    % Calculate weighted average next
    NL=0;    % same as cleared (i,j) but for simplicity
    Z =0;    % sum of all s(i,j)
    % Run loop through all the pixels in similarity window
    for r=rmin:rmax
        for s=smin:smax
            % neighborhood of pixel 'j' being compared for similarity
            W2 = I(r-f:r+f, s-f:s+f);
            % square of weighted euclidian distances
            d2 = sum(sum(kernel.*(W1-W2).*(W1-W2)));   %LINE 67
            % weight of similarity between both pixels : s(i,j)
            sij = exp(-d2/(h*h));
            % update Z and NL
            Z = Z + sij;
            NL = NL + (sij*I(r,s));
        end
    end
    % normalization of NL
    cleared(i,j) = NL/Z;
end
end
% convert cleared to uint8
cleared = uint8(cleared);

end 

但这给了我一个随后的错误:

使用。*时出错 整数只能与相同类的整数或标量双精度数组合。

Non_Local_Means错误(第67行)                 d2 = sum(sum(sum.kernel。(W1-W2)。(W1-W2)));

filter_process错误(第32行)                 eval(['filter_Images。',name_of_cells {i},'(',num2str(m),')','。',column_name {n},'((:,:,',num2str(p),') = Non_Local_Means(filter_Images。',name_of_cells {i},'(',num2str(m),')','。',column_name {n},'(:,:,',num2str(p),'), f,t,h);'])

无标题> pushbutton13_Callback中的错误(第1157行) handles.filtered_Images = filter_process(Images,f,t,h);

gui_mainfcn错误(第95行)         feval(varargin {:});

无标题错误(第42行)     gui_mainfcn(gui_State,varargin {:});

@(hObject,eventdata)中的错误无标题('pushbutton13_Callback',hObject,eventdata,guidata(hObject))

评估UIControl回调时出错

如何解决此问题(第67行)? 预先谢谢你!

0 个答案:

没有答案