How to divide the sum of convolution value in matlab syntax?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I'm colvolving an image by using my own kernel as in the syntax. The question is, how can i get the average 1/9 for each of the convolution point as normally used in the smoothing process.
I = imread('C:\\MEKH\\conveg.jpg');
figure, imshow(I);
J=rgb2gray(I);
figure, imshow(J)
A = [1,1,1;1,1,1;1,1,1]
%how to get the average eg here 1/9
B = conv2(A,J)
figure, imshow(B)
Thanks
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 6월 13일
편집: Ameer Hamza
2020년 6월 13일
Use this kernel for smoothing the image
A = [1,1,1;1,1,1;1,1,1]/9;
Also, it is better to use the image as the first input to conv2 and the kernel as second
B = conv2(J,A)
in the default setting, there is no difference. However, if you specify a different 'shape' option, then your approach can cause problems.
If you have, image processing toolbox, you can also use imfilter(): https://www.mathworks.com/help/releases/R2020a/images/ref/imfilter.html
You can also create the kernel using following command
A = fspecial('average',3) % requivalent: A = [1,1,1;1,1,1;1,1,1]/9;
추가 답변 (1개)
Haritha GB
2020년 6월 13일
I'm not entirely sure what your question means, since I am not familiar with the smoothing process.
From what I gather, you either want to a) find the sum of the entire output matrix elements and then divide by nine, or you want to b) divide each element of the output matrix by nine.
Either way the implementation line of code must come after calculating the convolution, i.e, put it after this line:
B = conv2(A,J)
So, for a)
m = length(B);
sum = 0;
for i = 1:m
sum = sum + B[i];
end
average = sum/9
And for b)
AVG = B/9
Hope I answered your question.
If you had intended otherwise with the question, let me know so I could answer it.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!