get error while creating nl filter

1 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Filter Banks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by