MATLAB: How to pass a function as a input parameter in nlfilter

Image Processing Toolboxinput parameternlfilter

I'm working on a binary image, and I want to do an operation that implies the count of the number of pixels with a specific value of a pixel neighbourhood, and depending on this result, substitute the current center pixel value by this result.
I have thought about the use of sliding neighbourhood operations, specifically "nlfilter". Therefore, my question is related to the use of this function.
I should specify what kind of function handle I would like to use, but I am not sure about the correct syntax of it.
For example, I thought a function like that (considering a [4 1] block):
function z=count(binIm,fixedCol);
for i=1:4
if binIm(i,fixedCol)=255
count=count+1;
end
end
if count>2
binIm(floor(([m n]+1)/2))=255;
end
So, the problem that I have is how can I translate it if I want to pass this function count() as a parameter at nlfilter. I don't know how the block is passed by parameters and what I should change in my function in order to do this operation.
Thanks.

Best Answer

See my attached demo for nlfilter.