1
votes

Assume that I have greyscale image I that have 300 x 300

and I have matrix matrix M 3 x 3

after the convolution

Ans = conv2(I,M);

ans will be matrix 304 x 304 => convolute will extend the matrix

If I want the answer to be a matrix like I Can I force it like

Ans = Ans(1+2:304-2;1+2:304-2); 
2
ans would actually be a matrix of size 302 x 302 - nmante

2 Answers

3
votes

Try the options in conv2

Ans = conv2(I,M,'same');
0
votes

You can use conv2(Image, Kernel, 'same'):

>> load clown % X = image of a clown
>> size(X)

ans =

   200   320

>> I = ones(10, 10);
>> size(conv2(X, I))

ans =

    209   329

>> size(conv2(X,I,'same'))

ans =

    200   320