How can I implement the following formula? Please write the code for it. Thanks.
y[n,m]= 1/3( x[n,m1] + x[n,m] + x[n,m+1] )

 채택된 답변

Image Analyst
Image Analyst 2021년 4월 17일

0 개 추천

kernel = [1,1,1]/3;
y = conv(x, kernel, 'same'); % Convolution does that. All rows, one row at a time.
or
y(n, :) = movmean(x(n, :), 3); % For the nth row only.

댓글 수: 2

I think the second one would work. However I'm using this for a grayscale image which I've converted to a matrix of values between 0 and 1.
And n and m are the independent variables (integer indices) indexing the pixels (matrix elements) along the vertical and horizontal dimensions of the image, respectively. Which i have obtained using the following (suppose A is the matrix):
n = size(A, 1);
m = size(A, 2);
How can I use this to define y and x for the equation above?
I suppose y can be:
y = zeros(n, m, 'logical');
But what about x? And is this approach correct?
Do you want to blur all the rows with a 1-by-3 array? If so you can use conv2 or imfilter
kernel = [1,1,1]/3;
y = conv(grayImage, kernel, 'same'); % Convolution does that. All rows, one row at a time.
y = imfilter(grayImage, kernel)
Or do you want to blur just the nth row and leave the other rows unchanged?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alan Stevens
Alan Stevens 2021년 4월 17일

0 개 추천

Change the square brackets, [ ], to curved brackets, ( ). Put a multiply sign, *, after the 3.

댓글 수: 2

Sarah Maas
Sarah Maas 2021년 4월 17일
No, I need it in a sort of a for loop for each M
Image Analyst
Image Analyst 2021년 4월 17일
OK, if you don't know how to do a for loop, then you have not even taken the most basic training on MATLAB. So follow this link and learn how to do simple things like for loops, if statements, assignments, referencing elements in an array, etc.:

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

질문:

2021년 4월 17일

댓글:

2021년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by