1
$\begingroup$

I try to filter an image using this equation: $$ I_f(x_j, y_k, t)=\sum_{p=-q}^q\sum_{r=-q}^q I(x_{j+p}, x_{k+r}, t) $$

where $I$ is the original image in grayscale, $I_f$ is the filtered image and $d$ is the subset. Here, I chose 3. However, I'm confused what will happen when $j=1$, $k=1$, and $p=-q$, $r=-q$.

Looping in MATLAB will result in error:

I=rand(240, 320);
[m, n]=size(I);
I_f=zeros(m,n);
d=3;
q=(d-1)/2;
for x=q:n
    for y=q:m
        for r=-q:q
            for p=-q:q
                I_f(x,y)=I(x+p,y+r);
            end
        end
    end
end

How to do it correclty in matlab? Is it possible to do it without looping? Thanks in advnace!

$\endgroup$
2
  • 3
    $\begingroup$ The equation, simply applies a summation mask on the image. It seems you've misunderstand the image filtering. Simply use this code , "q=10;p=10;Mask=ones(q,q);I_f=imfilter(I,Mask);" .You need study image spatial operations. $\endgroup$
    – MimSaad
    Mar 23, 2017 at 7:01
  • $\begingroup$ Thanks for the tip. Sorry I'm quite new in image processing. Anyway, I tweaked the code accordingly. d=3;Mask=ones(d,d)/9;I_f=imfilter(I,Mask, 'replicate'); $\endgroup$ Mar 23, 2017 at 7:47

1 Answer 1

1
$\begingroup$

The equation, simply applies a summation mask on the image. It seems you've misunderstand the image filtering. Simply use this code:

q=10;
p=10;
Mask=ones(q,q);
I_f=imfilter(I,Mask);

This is the comment by MimSaad converted into an answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.