What does the color window radius in pyrMeanShiftFiltering mean?

2.9k views Asked by At

My understanding of a RGB color vector is that it has 3 components like [100, 100, 100]. However, from the documentation, the argument sr – The color window radius in the Python function cv2.pyrMeanShiftFiltering(src, sp, sr[, dst[, maxLevel[, termcrit]]]) accepts an int.

What exactly does color radius mean? I'd also like to understand the min and max values, and what the units are in.

1

There are 1 answers

2
Soltius On BEST ANSWER

Based on what I read in the description of the algorithm from the documentation, sr is a parameter for a part of the algorithm which needs neighbor identification.

You might want to brush over your understanding of the mean shift algorithm, but at some point for a given pixel (X,Y), you need to find its neighbors. While often, we think as neighbors as spatial neighbors, i.e. pixels close spatially to the one we're considering ( ||(X,Y)-(x,y)||< some radius, with X,Y the considered pixel position and x,y the potential neighbor position), here the algorithm also considers the "color" closeness, as seen in the line :

the pixel (X,Y) neighborhood in the joint space-color hyperspace is considered:

(x,y): X- sp < x < X + sp , Y- sp < y < Y+ sp, ||(R,G,B)-(r,g,b)|| < sr

This means to be considered a neighbor, a pixel needs to be spatially close and have also a close color to the considered pixel. You set this closeness condition with sr, just like you set required spatial closeness with sp. Try some values out. It depends on what definition the algorithm uses for the || norm, probably something like ||(R,G,B)-(r,g,b)|| = sqrt((R-r)**2+(G-g)**2+(B-b)**2)