Sliding Neighbourhood Operation (Image Filtering)

조회 수: 1 (최근 30일)
Salad Box
Salad Box 2019년 10월 30일
편집: Salad Box 2019년 10월 30일
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.

답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by