How can i perform manual convolution in an image MxNx3

조회 수: 9 (최근 30일)
Gn Gnk
Gn Gnk 2021년 4월 7일
댓글: DGM 2023년 12월 1일
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