get error while creating nl filter

2 visualizaciones (últimos 30 días)
Enes Halid AYDIN
Enes Halid AYDIN el 18 de Nov. de 2021
Respondida: prabhat kumar sharma el 4 de Abr. de 2024
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.

Respuestas (1)

prabhat kumar sharma
prabhat kumar sharma el 4 de Abr. de 2024
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!

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by