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:
I
. 3X3
. m
and standard deviation s
from the mask. t1 = ms
and t2 = m+s
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)
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.
blockproc gives you distinct blocks. Instead use nlfilter.
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(:))
.
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)
下一篇: 错误:MATLAB中的图像噪声检测