MATLAB Answers

Selecting pixel of image

9 views (last 30 days)
I am trying to manipulate the pixel of image by using a window.
Can someone help me?
Thanks in advance


Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 30 Oct 2020
boxFilter = ones(2*k+1);
U = imfilter(I, boxFilter);

  1 Comment

Image Analyst
Image Analyst on 30 Oct 2020
Or almost equivalently
U = conv2(double(I), boxFilter, 'same');
because if I is a uint8 image, you need to cast to double first. Also, if you want your output image to be the same size as the input image (not larger) then you need to use the 'same' option. U will then be a double image in the same range as your input image, like 0-255 or 0-1 or 0-65535 depending on what class I is. If you want it to be a uint8 again, you can cast it to uint8. Or you can leave it as double but just use [] as the second input argument in imshow() when you go to display U.

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 30 Oct 2020
This is equation for 2D convolution. Use conv2():
For example,
I; % your image
k = 3;
B = ones(k*2+1);
U = conv2(I, B);


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by