Statistical mode?

Private: Q&ACategory: Feature requestStatistical mode?
mdimitri asked 8 years ago

Is this a feature which is lacking? I can’t seem to find any implementation in the provided scripts.
I need a 2D implementation to search for the most frequently occuring pixel value in an image patch.

2 Answers
sdonn answered 8 years ago

Could you just use the image histogram with 256 bins? It can be found in imhist.q

bgoossen answered 8 years ago

immedfilt.q contains an implementation of “moving histograms”. This is: a 2D window moves over the image and the local histogram is updated row-by-row. immedfilt then simply calculates the median in a very efficient way (and in parallel) using this technique.
What you could do is start from the implementation in immedfilt.q and adjust it to calculate to most frequently occuring pixel value (i.e. mode of the histogram). You’ll need to replace the function:

y[m, p] = compute_median(hist_im, p, N, idx_median)

by your own function to calculate the mode.
Basically, hist_im here has dimensions bins x cols. It contains the local histograms for row ‘m’. Let us know if you need further assistance.