-1

I have an image which matrix has some pixels with value NaN. For such certain pixel, I want to compare its 8-neighbourhood, and assign it a value based on that neighborhood.

I think for the neighbourhood we use nlfilter?

How can I do that in matlab?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

1

You could decide by isnan, e.g.

M = nlfilter(M, [3,3], @neighFun);

function ret = neighFun(x)
    if isnan(x(2,2))
        ret = whatever;
    else
        ret = x(2,2);
    end
end
matheburg
  • 2,097
  • 1
  • 19
  • 46
  • @matheburg.Thanks for your reply. What does `@` preceding the function name mean? – Simplicity Apr 26 '13 at 23:53
  • 1
    @neighFun is a [function handle](http://www.mathworks.de/de/help/matlab/ref/function_handle.html). That means you hand over a reference to neighFun to nlfilter. Without "@" it would try to call neighFun and hand over the return value to nlfilter. – matheburg Apr 27 '13 at 00:07