2D majority filer in MATLAB?

조회 수: 7 (최근 30일)
Elena Ranguelova
Elena Ranguelova 2017년 2월 24일
답변: rgr478 2021년 7월 7일
Hello,
Is there a 2D majority filter in MATLAB?
With ordfilt2 minimum, maximum, median etc. filters can be implemented, but not majority. Is there another command with that functionality?
Here 'majority filter' means replacing each element of a matrix by the most frequently occurring element in a set of neighbors of that element.
Regards, Elena
  댓글 수: 1
Elena Ranguelova
Elena Ranguelova 2017년 2월 24일
Maybe
blockproc
would help?
fun = @(block_struct) ...
mode(block_struct.data(:)) * ones(size(block_struct.data));
output_matrix = blockproc(input_matrix,[<size_x> <size_y>],fun);

댓글을 달려면 로그인하십시오.

답변 (3개)

Sailesh Sidhwani
Sailesh Sidhwani 2019년 5월 22일
편집: Sailesh Sidhwani 2019년 5월 22일
There is no direct function for mode filtering, you can use the colfilt instead:
out = colfilt(img, [5 5], 'sliding', @mode) ;

Sailesh Sidhwani
Sailesh Sidhwani 2020년 11월 25일
A new 'modefilt' function for 2D and 3D data was added to Image Processing Toolbox in R2020a:
Both 'colfilt' and 'nlfilter' are generic sliding window functions and can be used to perform mode filtering but the expectation is that 'modefilt' to be faster than both of these functions and also work on 3D grayscale data.

rgr478
rgr478 2021년 7월 7일
bwmorph(image,'majority')

Community Treasure Hunt

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

Start Hunting!

Translated by