# 2d convolution

Discussion in 'Programmer's Corner' started by teen devil, Apr 15, 2010.

1. ### teen devil Thread Starter Active Member

Apr 6, 2009
47
0
HEY GUYS I AM TRYING TO CONVOLVE 2 IMAGES BUT THE MATLAB IS GIVING ME THE ERROR WHERE I AM USING CONV2 COMMAND ... HERE IS CODING
c1 = conv2(i1,i2)
or
c1 = conv2(i1,i2,'valid')
both lines of c1 is not working
and the error is comming from line of c1...
I AM WAITING FOR UR HELP GUYS!!!

2. ### guitarguy12387 Active Member

Apr 10, 2008
359
12
You might want to tell us the specific error...

3. ### teen devil Thread Starter Active Member

Apr 6, 2009
47
0
the error is :

Error in ==> convolution at 4
c1=conv2(i1,i2);

4. ### teen devil Thread Starter Active Member

Apr 6, 2009
47
0
can anybody help......

5. ### johndoe45 Member

Jan 30, 2010
364
1
i don't know. but i found something similar to this. and modified it to match yours. i'm guessing you just need an h matrix

clc
clear all
close all

h = [0 1 0, 1 -4 1, 0 1 0];
A1=conv2(A,:,1),h,'same');
A2=conv2(B,:,2),h,'same');
A,:,1)=A1;
A,:,2)=A2;

subplot(121),imshow(A),title('image filtrée');
zoom on;

subplot(122),imshow(A),title('panchromatique filtrée');
zoom on;

Last edited: Apr 20, 2010
6. ### teen devil Thread Starter Active Member

Apr 6, 2009
47
0
ITS GIVING ERROR JHON

??? Subscripted assignment dimension mismatch.

Error in ==> kl at 11
A,:,2)=A2;

7. ### teen devil Thread Starter Active Member

Apr 6, 2009
47
0
HEY BUT WHEN I CHANGED A TO B SO NOW COING BECOMES
clc
clear all
close all

h = [1 2 1, 0 0 0, -1 -2 -1];
A1=conv2(A,:,1),h,'same');
A2=conv2(B,:,2),h,'same');
A,:,1)=A1;
B,:,2)=A2;

subplot(121),imshow(A),title('image filtrée');
zoom on;

subplot(122),imshow(A),title('panchromatique filtrée');
zoom on;
IT GIVES 2 IMAGES BUT WITH NO DIFFERENCE

8. ### johndoe45 Member

Jan 30, 2010
364
1
of course it gives you two images. i was just showing you that hey it works this way. i don't know what the code means. it was just to show you that it could be just that there is something wrong with the vectors. and h in previous made it work.

clc
clear all
close all