私はMatlabでファジーインパルスノイズの検出方法を実装しようとしています。グレースケール画像の各非境界画素について、中心画素の8つの可能なすべての近隣の異なる勾配を計算し、ファジー規則をチェックし、その画素が騒々しいかどうかを検出する3 * 3ウィンドウを定義する。しかし、それはちょうど最初のピクセルを通過し、正しく計算します。 2番目のピクセルのために私は次のエラーを取得します。誰でも助けてくれますか? さらに、グラデーションを計算するための関数を定義しようとしていますが、これはすべての方向に対してそのような関数を定義できるのですか? エラー:Matlabのファジーインパルスノイズ検出
インデックスが行列の寸法を超えています。
メイン(29行目)のエラー g2 = double(img_temp(r、c + 1) - img_temp(r、c));ここ
と
は私のコードです:close all
clc
[file, path] = uigetfile('*.*' , 'Open an image');
filename = strcat(path, file);
img = (imread(filename));
dim = ndims(img);
if (dim==3)
img = rgb2gray(img);
end
figure, imshow(img);
k = 1;
[row , col] = size(img);
for r=2:row-1
largeCount = 0;
for c=2:col-1
img_temp = img(r-1:r+1, c-1:c+1);
%% Gradient Calculation in Direction : N
g0 = double(img_temp(r-1,c) - img_temp(r,c));
g1 = double(img_temp(r, c-1) - img_temp(r,c));
g2 = double(img_temp(r, c+1) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : NE
g0 = double(img_temp(r-1 , c+1) - img_temp(r,c));
g1 = double(img_temp(r-1, c-1) - img_temp(r,c));
g2 = double(img_temp(r+1 , c+1) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : E
g0 = double(img_temp(r,c+1) - img_temp(r,c));
g1 = double(img_temp(r-1,c) - img_temp(r,c));
g2 = double(img_temp(r+1 ,c) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : SE
g0 = double(img_temp(r+1, c+1) - img_temp(r,c));
g1 = double(img_temp(r-1 , c+1) - img_temp(r,c));
g2 = double(img_temp(r+1 , c-1) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : S
g0 = double(img_temp(r+1, c) - img_temp(r,c));
g1 = double (img_temp(r , c+1) - img_temp(r,c));
g2 = double(img_temp(r , c-1) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : SW
g0 = double(img_temp(r+1, c-1) - img_temp(r,c));
g1 = double(img_temp(r+1 , c+1) - img_temp(r,c));
g2 = double(img_temp(r-1, c-1) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : W
g0 = double(img_temp(r,c-1) - img_temp(r,c));
g1 = double(img_temp(r+1, c) - img_temp(r,c));
g2 = double(img_temp(r-1, c) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : NW
g0 = double(img_temp(r-1,c-1) - img_temp(r,c));
g1 = double(img_temp(r+1 , c-1) - img_temp(r,c));
g2 = double(img_temp(r-1 , c+1) - img_temp(r,c));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
k = k+1;
end
%% if largeCount > 4 then the pixel is noisy for sure
if largeCount> 4
%% Add the pixel value to histogram
out(r,c)= 0;
else
%% Don't change pixel value
output(r,c) = (temp(r,c));
end
end
figure ; imshow(output);
編集:私は、しかし、私のコードを変更した
私は、次のコードを実行していながら、それが一時停止します(関数呼び出しスタック:ismemeber)とドン私にimg_outを表示しないでください。このエラーが発生します。
69 [sortuAuB、IndSortuAuB] = sort([uA; uB]);
close all
clc
[file, path] = uigetfile('*.*' , 'Open an image');
filename = strcat(path, file);
img = (imread(filename));
dim = ndims(img);
if (dim==3)
img = rgb2gray(img);
end
figure, imshow(img);
k = 1;
out = readfis('NoiseDetection.fis');
[row , col] = size(img);
img_out = zeros(row , col , 'uint8');
for r=2:row-1
largeCount = 0;
for c=2:col-1
img_temp = img(r-1:r+1, c-1:c+1);
%% Gradient Calculation in Direction : N
g0 = double(img_temp(1,2) - img_temp(2,2));
g1 = double(img_temp(2,1) - img_temp(2,2));
g2 = double(img_temp(2,3) - img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : NE
g0 = double(img_temp(1,3) - img_temp(2,2));
g1 = double(img_temp(1,1) - img_temp(2,2));
g2 = double(img_temp(3,3) - img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : E
g0 = double(img_temp(2,3) - img_temp(2,2));
g1 = double(img_temp(1,2) - img_temp(2,2));
g2 = double(img_temp(3,2) - img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : SE
g0 = double(img_temp(3,3) - img_temp(2,2));
g1 = double(img_temp(1,3) - img_temp(2,2));
g2 = double(img_temp(3,1) - img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : S
g0 = double(img_temp(3, 2)- img_temp(2,2));
g1 = double(img_temp(2, 3)- img_temp(2,2));
g2 = double(img_temp(2 ,1)- img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : SW
g0 = double(img_temp(3,1) - img_temp(2,2));
g1 = double(img_temp(3,3) - img_temp(2,2));
g2 = double(img_temp(1,1) - img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : W
g0 = double(img_temp(2,1)- img_temp(2,2));
g1 = double(img_temp(3,2)- img_temp(2,2));
g2 = double(img_temp(1,2)- img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% Gradient Calculation in Direction : NW
g0 = double(img_temp(1,1)- img_temp(2,2));
g1 = double(img_temp(3,1)- img_temp(2,2));
g2 = double(img_temp(1,3)- img_temp(2,2));
g_weight = max (max (evalfis([g0 g1 0],out) , evalfis([g0 0 g2],out)), evalfis([g0 g1 g2],out));
if g_weight >128
largeCount = largeCount+1;
end
%% if largeCount > 4 then the pixel is noisy for sure
if largeCount> 4
%% Add the pixel value to histogram
img_out(r,c)=0;
else
%% Don't change pixel value
img_out(r,c) = img_temp(2,2);
end
end
k = k+1;
end
figure ; imshow(img_out);
ああ!そんなにありがとう、私はそれをやるつもりです。 – Shin
それを試してみてください! – rayryeng
それは働いています!ありがとう、あなた。 – Shin