60 views (last 30 days)

Show older comments

How can I implement the following formula? Please write the code for it. Thanks.

y[n,m]= 1/3( x[n,m−1] + x[n,m] + x[n,m+1] )

Image Analyst
on 17 Apr 2021 at 15:32

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.

Image Analyst
on 17 Apr 2021 at 16:34

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?

Alan Stevens
on 17 Apr 2021 at 14:20

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

Image Analyst
on 17 Apr 2021 at 15:27

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

Start Hunting!