How can i perform manual convolution in an image MxNx3

12 Ansichten (letzte 30 Tage)
Gn Gnk
Gn Gnk am 7 Apr. 2021
Kommentiert: DGM am 1 Dez. 2023
Hello ,
i want to perform manual convolution in an image with a filter (not using conv() or some matlab function) .The problem here that i was used to perform this convolution to images MxN , but in this case the image is MxNx3 . I thougth that maybe i should perform convolution 3 times like this :
%lets say that my image is I
I_conv1 = convolution(I(:,:,1),filter);
I_conv2 = convolution(I(:,:,2),filter);
I_conv3 = convolution(I(:,:,3),filter);
result = imadd(I_conv1 , I_conv2);
resultFinal = imadd(result , I_conv3);
But i dont get the result i want .
Can someone help me here ?
If you want to check my code for the manual convolution let me know in the comments . I am not providing it here because the question is going to be very long .
  3 Kommentare
manikandan
manikandan am 1 Dez. 2023
function convImage = convolution( image,kernel,numLayers , filterSize )
what is the use of this line

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

DGM
DGM am 7 Apr. 2021
Bearbeitet: DGM am 7 Apr. 2021
I'm not sure why you expect the convolution of a MxNx3 image with an IxJx1 filter to be a MxNx1 image. It would be a MxNx3 image. You'd just concatenate the three passes into one image
Rf = convolution(I(:,:,1),filter);
Gf = convolution(I(:,:,2),filter);
Bf = convolution(I(:,:,3),filter);
output=cat(3,Rf,Gf,Bf);
Are you intending on using 3D filters (e.g. IxJx2 or IxJx3)? If so, all you would need to do is pad the image along dim3 and add another outer loop to the convolution routine so that you traverse dim3 just the same as you did the others.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by