Sliding Neighbourhood Operation (Image Filtering)
2 次查看(过去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/245764/image.jpeg)
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 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!