简体   繁体   中英

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) . A sliding window of size 3X3 centered at I(x, y) is defined. 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. If the pixel is between ms and m+s , then it is a signal otherwise noise and we will apply median filter.

Algorithm:

  1. Read an image I .
  2. Take a sliding window or mask of size 3X3 .
  3. Calculate the mean m and standard deviation s from the mask.
  4. Calculate the threshold as follows: t1 = ms and t2 = 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.
  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:

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. Instead use nlfilter.

  2. iout(i,j)=medfilt2(y(i,j)) is a wrong statement. medfilt2 only does median filtering, it doesn't give you the median. To get the median value, just use median(y(:)) .

  3. This is wrong : (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

Explanation to $3^rd$ is given in the above link.

This means you did not assign anything to your output parameter. I guess you should assign to x rather then iout (i, j)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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