How can I tune the threshold in majority operation with BWMORPH in Image Processing Toolbox 6.1 (R2009a)? The majority action in BWMORPH sets a pixel to 1 if five or more pixels in its 3-by-3 neighborhood are 1s; otherwise, it sets the pixel to 0. I would like to do it with a number different from five.
John Michell answered .
2025-11-20
function Result = MyBWMorph (BW, n) f = @(x) (sum(x(:)) >= n); lut = makelut(f,3); Result = applylut (BW, lut);
This function sets a pixel from the BW image to 1 if 'n' or more pixels in its 3-by-3 neighborhood are 1, otherwise, it sets the pixel to 0.