[英]Error: Image Noise detection in MATLAB
在實現用於圖像中噪聲檢測的簡單想法時出現錯誤。 讓I
表示嘈雜的圖像,並為I
每個像素表示I(x,y)
。 定義了一個以I(x, y)
為中心的大小為3X3
滑動窗口。 首先,我們估計窗口的中心像素是否為噪點。 為了區別噪聲和信號,我們計算窗口的平均值m
和標准偏差s
。 如果像素在ms
到m+s
,那么這是一個信號,否則就是噪聲,我們將應用中值濾波器。
算法:
I
3X3
的滑動窗口或蒙版。 m
和標准偏差s
。 t1 = ms
和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)
我嘗試如下實現此算法
clc;
close all;
clear all;
I=imread('lena.jpg');
I=rgb2gray(I);
Out = blockproc(I,[3 3],@(x) noisedetection(x.data(:)));
imshow(out);
功能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
但是我收到以下錯誤
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(:)));
請幫我。
blockproc為您提供了不同的塊。 而是使用nlfilter。
iout(i,j)=medfilt2(y(i,j))
是錯誤的語句。 medfilt2僅執行中值過濾,而不會提供中值。 要獲得中值,只需使用median(y(:))
。
這是錯誤的: (t1<=y(i,j) & y(i,j)<=t2)
。
另外,您還可以交叉發布。 檢出: https : //dsp.stackexchange.com/questions/15033/error-image-noise-detection-in-matlab/15036?noredirect=1#comment25759_15036
$ 3 ^ rd $的說明在上面的鏈接中給出。
這意味着您沒有為輸出參數分配任何內容。 我猜你應該分配給x
而不是iout (i, j)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.