Sliding Neighbourhood Operation (Image Filtering)

2 views (last 30 days)
Salad Box
Salad Box on 30 Oct 2019
Edited: Salad Box on 30 Oct 2019
Hi,
I have a sample image and I would like to apply a 4 by 5 'sliding block' to this image.
In each 4 x 5 block, I would like to use the center pixel of that block to represent this block.
Here is what I tried:
fn = '002.png';
I = imread(fn);
m = 4;
n = 5;
% the center pixel is floor(([m n]+1)/2)
f = @(x) x(floor(([m n]+1)/2),:);
I2 = nlfilter(I,[4 5],f);
figure
imshow(I2)
What I get is
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the
right side is 2-by-5.
Error in nlfilter (line 76)
b(i,j) = feval(fun,x,params{:});
I'm guessing the bug is in the 'f', but I don't know how to modify it.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!