I created a code which does filtering with convulution but it gives an error

1 回表示 (過去 30 日間)
Demet Bayraktar
Demet Bayraktar 2021 年 7 月 27 日
コメント済み: Demet Bayraktar 2021 年 7 月 27 日
A = imread('lena.jpg');
F = uint8([-1 -1 -1;0 0 0;1 1 1]);
B = uint8(padarray(A,[1 1]));
Output = uint8(zeros(size(A)));
for i = 1:size(B,1)-2
for j = 1:size(B,2)-2
X = B(i:i+2,j:j+2).*F;
Output(i,j) = sum(X(:));
end
end
imshow(Output)
but it doesn't work correctly. What is my mistake?
  1 件のコメント
Rik
Rik 2021 年 7 月 27 日
Why do you want to replace the efficient convolution with a nested loop?

サインインしてコメントする。

採用された回答

Chunru
Chunru 2021 年 7 月 27 日
The image has 3 channels and is a 3D array. You need to loop over the 3rd dimension as well. Use a different image below.
A = imread('onion.png');
F = uint8([-1 -1 -1;0 0 0;1 1 1]);
B = uint8(padarray(A,[1 1]));
Output = uint8(zeros(size(A)));
for k=1:size(B,3)
for i = 1:size(B,1)-2
for j = 1:size(B,2)-2
X = B(i:i+2,j:j+2, k).*F;
Output(i,j, k) = sum(X(:));
end
end
end
subplot(121)
imshow(A)
subplot(122)
imshow(Output)
  1 件のコメント
Demet Bayraktar
Demet Bayraktar 2021 年 7 月 27 日
it worked perfectly when i use different image. thank you for your help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by