someone
someone

Reputation: 365

how to adjust matrix after convolution MATLAB

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); 

Upvotes: 1

Views: 715

Answers (2)

Gastón Bengolea
Gastón Bengolea

Reputation: 865

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

Upvotes: 0

lennon310
lennon310

Reputation: 12689

Try the options in conv2

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

Upvotes: 3

Related Questions