Majority filter to classify true white and black pixels from a thresholded image
3 次查看(过去 30 天)
显示 更早的评论
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 ?
0 个评论
采纳的回答
Image Analyst
2014-4-24
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!