简体   繁体   English

错误:MATLAB中的图像噪声检测

[英]Error: Image Noise detection in MATLAB

I am getting error while implementing a simple idea for noise detection in an image. 在实现用于图像中噪声检测的简单想法时出现错误。 Let I denote noisy image and for each pixel of I is represented by I(x,y) . I表示嘈杂的图像,并为I每个像素表示I(x,y) A sliding window of size 3X3 centered at I(x, y) is defined. 定义了一个以I(x, y)为中心的大小为3X3滑动窗口。 At first, we estimate that the center pixel of window is noise or not. 首先,我们估计窗口的中心像素是否为噪点。 To differ the noise and signal, we calculate the mean m and standard deviation s of the window. 为了区别噪声和信号,我们计算窗口的平均值m和标准偏差s If the pixel is between ms and m+s , then it is a signal otherwise noise and we will apply median filter. 如果像素在msm+s ,那么这是一个信号,否则就是噪声,我们将应用中值滤波器。

Algorithm: 算法:

  1. Read an image I . 读取图像I
  2. Take a sliding window or mask of size 3X3 . 采取大小为3X3的滑动窗口或蒙版。
  3. Calculate the mean m and standard deviation s from the mask. 计算与蒙版的平均值m和标准偏差s
  4. Calculate the threshold as follows: t1 = ms and t2 = m+s 计算阈值如下: t1 = mst2 = m+s
  5. IF t1 <= I(x,y) and I(x,y) <= t2, THEN Result(x,y) = I(x,y) ELSE Result(x, y) = medfilt2(I(x,y)
  6. Repeat the step 3 , 4 and 5 on entire Image. 在整个图像上重复步骤3、4和5。
  7. Display the resultant image. 显示结果图像。

I tried to implement this algorithm as follows 我尝试如下实现此算法

clc;
close all;
clear all;

I=imread('lena.jpg');
I=rgb2gray(I);

Out = blockproc(I,[3 3],@(x) noisedetection(x.data(:)));

imshow(out);

The function noisedetection is given as below: 功能noisedetection如下:

function x=noisedetection(y)
s=std2(y(:)); % Calculating Standard deviation
m=mean2(y(:)); % Calulating Mean
t1=m-s; % Threshold 1
t2=m+s; % Threshold 2
[m n]=size(y);

for i=1:m
    for j=1:n


if (t1<=y(i,j) & y(i,j)<=t2)
    iout(i,j)=y(i,j)
else
    iout(i,j)=medfilt2(y(i,j)) % Filtering only when the pixel does not fall in the interval [t1,t2] 
end
    end
end
x=iout

But I am getting the following error 但是我收到以下错误

    Subscripted assignment dimension mismatch.

Error in blockprocInMemory (line 151)
    b(last_row_start:end,last_col_start:end,:) = lr_output;

Error in blockproc (line 237)
    result_image = blockprocInMemory(source,fun,options);

Error in detection (line 8)
Out = blockproc(I,[3 3],@(x) noisedetection(x.data(:)));

Please help me. 请帮我。

  1. blockproc gives you distinct blocks. blockproc为您提供了不同的块。 Instead use nlfilter. 而是使用nlfilter。

  2. iout(i,j)=medfilt2(y(i,j)) is a wrong statement. iout(i,j)=medfilt2(y(i,j))是错误的语句。 medfilt2 only does median filtering, it doesn't give you the median. medfilt2仅执行中值过滤,而不会提供中值。 To get the median value, just use median(y(:)) . 要获得中值,只需使用median(y(:))

  3. This is wrong : (t1<=y(i,j) & y(i,j)<=t2) . 这是错误的: (t1<=y(i,j) & y(i,j)<=t2)

Plus you have cross-posted. 另外,您还可以交叉发布。 Check out : https://dsp.stackexchange.com/questions/15033/error-image-noise-detection-in-matlab/15036?noredirect=1#comment25759_15036 检出: https : //dsp.stackexchange.com/questions/15033/error-image-noise-detection-in-matlab/15036?noredirect=1#comment25759_15036

Explanation to $3^rd$ is given in the above link. $ 3 ^ rd $的说明在上面的链接中给出。

This means you did not assign anything to your output parameter. 这意味着您没有为输出参数分配任何内容。 I guess you should assign to x rather then iout (i, j) 我猜你应该分配给x而不是iout (i, j)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM