How can i perform manual convolution in an image MxNx3

25 次查看(过去 30 天)
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 个评论
manikandan
manikandan 2023-12-1
function convImage = convolution( image,kernel,numLayers , filterSize )
what is the use of this line

请先登录,再进行评论。

采纳的回答

DGM
DGM 2021-4-7
编辑:DGM 2021-4-7
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.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by