How can i perform manual convolution in an image MxNx3

12 vues (au cours des 30 derniers jours)
Gn Gnk
Gn Gnk le 7 Avr 2021
Commenté : DGM le 1 Déc 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 commentaires
manikandan
manikandan le 1 Déc 2023
function convImage = convolution( image,kernel,numLayers , filterSize )
what is the use of this line
DGM
DGM le 1 Déc 2023

Connectez-vous pour commenter.

Réponse acceptée

DGM
DGM le 7 Avr 2021
Modifié(e) : DGM le 7 Avr 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.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by