How can I tune the threshold in majority operation

Illustration
instenr_asds - 2022-02-24T12:55:08+00:00
Question: How can I tune the threshold in majority operation

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.

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

To apply a morphological operation on binary images similar to majority but with a different number of pixels as a threshold in Image Processing Toolbox 6.1 (R2009a) use the MAKELUT and APPLYLUT functions.
 
For example, you define the following function:
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.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!