Majority filter to classify true white and black pixels from a thresholded image

3 views (last 30 days)
I have a thresholded binary image. To reconfirm about the true white pixels corresponding the object and the true black pixels corresponding the background , I like to further scan the image by the 3X3 window and convolution process.
My questions are :
1.If I want a majority filter which will be replacing central pixel with the majority values of neighbors , what will be the matrix elements of the kernel of size 3X3? If I pre-define the central pixel as 0 to classify black pixels from the majority in neighbors, what will be other elements in kernel?
2. how can I count the no. of true black pixels after doing convolution
3. By the same way , can I also define a majority filter to classify and count true white pixels ?

Accepted Answer

Image Analyst
Image Analyst on 24 Apr 2014
That is simply a median filter:
newBinaryImage = medfilt2(binaryImage, [3, 3]);
You can also do it with a convolution if you threshold after the convolution to get windows with 5 or more "set" pixels in them:
counts = conv2(binaryImage, ones(3), 'same') >= 5;
Convolution may be faster than median filter.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!