Skip to content

ENH: ndimage: majority voting filter #9873

@skjerns

Description

@skjerns

ndimage.filters has quite useful filters, but in my opinion one filter could be implemented:
An occurrence based filter, such as a majority filter.

The filter would go over an array, count occurrences within the given window size and take the n-ths most occuring value as an output, e.g.:

arr = [1,1,2,3,4,4,5,6,6,6,7,8,8,8]
res = occurence_filter(arr, size=5, rank=-1,  mode='valid')
# pseudocode
for i in range(len(arr)-size):
    w = arr[i:i+size]
    occurences = count_unique_values(w) # e.g [2:1,3:1,4:1,1:2]
    ranked = occurences[rank] # =1
    res[i] = ranked
    
# res = [1,4,4,4,4,4,6,6,6,6,8]

would it make sense to implement such a filter?
Or is there any other way I can express such an operation that I haven't seen yet?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions