声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1522|回复: 1

[图像处理] (图像除噪)帮忙看看程序错在哪?

[复制链接]
发表于 2009-6-4 00:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
(图像除噪)帮忙看看程序错在哪?function [output]=NLmeansfilter(input,t,f,h)
% Size of the image
[m n]=size(input);


% Memory for the output
Output=zeros(m,n);

% Replicate the boundaries of the input image
input2 = padarray(input,[f f],'symmetric');

% Used kernel
kernel = make_kernel(f);
kernel = kernel / sum(sum(kernel));

h=h*h;

for i=1:m
for j=1:n
                 
         i1 = i+ f;
         j1 = j+ f;
               
         W1= input2(i1-f:i1+f , j1-f:j1+f);
         
         wmax=0;
         average=0;
         sweight=0;
         
         rmin = max(i1-t,f+1);
         rmax = min(i1+t,m+f);
         smin = max(j1-t,f+1);
         smax = min(j1+t,n+f);
         
         for r=rmin:1:rmax
         for s=smin:1:smax
                                               
                if(r==i1 && s==j1) continue; end;
                                
                W2= input2(r-f:r+f , s-f:s+f);               
                 
                d = sum(sum(kernel.*(W1-W2).*(W1-W2)));
                                               
                w=exp(-d/h);                 
                                 
                if w>wmax               
                    wmax=w;                  
                end
               
                sweight = sweight + w;
                average = average + w*input2(r,s);                                 
         end
         end
            
        average = average + wmax*input2(i1,j1);
        sweight = sweight + wmax;
                  
        if sweight > 0
            output(i,j) = average / sweight;
        else
            output(i,j) = input(i,j);
        end               
end
end

function [kernel] = make_kernel(f)              

kernel=zeros(2*f+1,2*f+1);   
for d=1:f   
  value= 1 / (2*d+1)^2 ;   
  for i=-d:d
  for j=-d:d
    kernel(f+1-i,f+1-j)= kernel(f+1-i,f+1-j) + value ;
  end
  end
end
kernel = kernel ./ f;

      调用上面的函数执行下面的程序(找一bmp图片命名lena.bmp)

clear
clc
clf
colormap(gray)

% create example image
ima=imread('lena.bmp')
imagesc(ima);
fs=fspecial('average');
ima=imfilter(ima,fs,'symmetric');

% add some noise
sigma=10;
rima=ima+sigma*randn(size(ima));

% show it
%imagesc(rima)
%drawnow

% denoise it
fima=NLmeansfilter(ima,5,2,sigma);

% show results
clf

subplot(2,2,1),imagesc(ima),title('original');
subplot(2,2,2),imagesc(rima),title('noisy');
subplot(2,2,3),imagesc(fima),title('filtered');
subplot(2,2,4),imagesc(rima-fima),title('residuals');

运行之后出现错误:??? Error using ==> plus
Integers can only be combined with integers of the same class, or scalar doubles.Error in ==> demo22 at 14
rima=ima+sigma*randn(size(ima)); 请高手指教。谢谢

[[i] 本帖最后由 wdtyang 于 2009-6-4 08:46 编辑 [/i]]
回复
分享到:

使用道具 举报

发表于 2009-6-4 07:39 | 显示全部楼层

回复 楼主 wdtyang 的帖子

建议楼主看下本版规则!
求助完整格式:出错代码和出错提示
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-6-7 03:42 , Processed in 0.047063 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表