get error while creating nl filter

2 ビュー (過去 30 日間)
Enes Halid AYDIN
Enes Halid AYDIN 2021 年 11 月 18 日
回答済み: prabhat kumar sharma 2024 年 4 月 4 日
I'm trying to create an nl filter with for loops. The coefficient values and dimension ​​of the filter must be entered by the user. I can understand the part up to here. But I get an error when applying the filter to the image, with the dimension data I get from the user. The code I wrote for the filter and the error image are attached. I would be very happy if you help.

回答 (1 件)

prabhat kumar sharma
prabhat kumar sharma 2024 年 4 月 4 日
Hi Enes,
I understand that you are facing some error in line 44:
fun2 = im(i:i+1,j:j+1).*filtre;
I understand that here you're extracting a sub-matrix of size 2x2 from im because i:i+1 and j:j+1 define a range that selects a 2x2 area.
However, filtre is created based on user input for its dimensions, which means its size can vary and does not necessarily match the 2x2 size of the sub-matrix from im.
To resolve this issue, you need to ensure that the size of the sub-matrix of im matches the size of filtre. This can be done by adjusting the range of indices used to extract the sub-matrix from im so that it matches the dimensions of filtre. Assuming filtre has dimensions r x c (which you've initially set to 11 x 11 but then later allow the user to define), you should modify the line as follows:
  1. Ensure filtre has the dimensions as intended by the user input or your initial setup.
  2. Adjust the sub-matrix extraction from im to match the dimensions of filtre.
Here's how you can adjust the problematic line,
% Correctly extracting a sub-matrix of im that matches the size of filtre
for i=1:size(im,1)-size(filtre,1)+1
for j=1:size(im,2)-size(filtre,2)+1
subMatrix = im(i:i+size(filtre,1)-1, j:j+size(filtre,2)-1);
fun2 = subMatrix .* filtre;
yi(i,j) = sum(fun2(:));
end
end
I hope it helps!

カテゴリ

Help Center および File ExchangeFilter Banks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by