Algorithm 3MeanShift(; ). |
1: |
K // the cluster result |
2: |
Pc // The position of the current pixel |
3: |
S // The temporal set |
4: |
ITR // The iteration number |
5: |
STOP // The flag that indicates all pixels do not move in the last iteration |
6: |
STOP ← False |
7: |
whileITR < 300 and STOP = False
do
|
8: |
for each pixel Pc of R
do
|
9: |
S ← ∅ |
10: |
for each neighboring pixel Pn of Pc using the window size W2
do
|
11: |
if the color of Pc does not equal to the background color then
|
12: |
Push Pn into S. |
13: |
end if
|
14: |
end for
|
15: |
Compute the new position for Pc based on S. |
16: |
end for
|
17: |
// Check if some of the pixels have new positions |
18: |
if none of the pixels in R moves then
STOP ← True
|
19: |
end if
|
20: |
end while
|
21: |
Give every separate component a distinct number, and assign the result to K. |
22 |
returnK. |