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:
- Ensure filtre has the dimensions as intended by the user input or your initial setup.
- 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!